rapx/analysis/core/api_dependency/graph/
dep_node.rs1use std::hash::Hash;
2
3use super::ty_wrapper::TyWrapper;
4use rustc_middle::{
5 query::IntoQueryParam,
6 ty::{self, Ty, TyCtxt},
7};
8
9use rustc_hir::def_id::DefId;
10
11#[derive(Clone, Copy, Eq, PartialEq, Hash, Debug)]
12enum IntrinsicKind {
13 Borrow,
14}
15
16#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
17pub enum DepNode<'tcx> {
18 Api(DefId, ty::GenericArgsRef<'tcx>),
19 Ty(TyWrapper<'tcx>),
20}
21
22pub fn desc_str<'tcx>(node: DepNode<'tcx>, tcx: TyCtxt<'tcx>) -> String {
23 match node {
24 DepNode::Api(def_id, args) => tcx.def_path_str_with_args(def_id, args),
25 DepNode::Ty(ty) => ty.desc_str(tcx),
26 }
27}
28
29impl<'tcx> DepNode<'tcx> {
30 pub fn api(id: impl IntoQueryParam<DefId>, args: ty::GenericArgsRef<'tcx>) -> DepNode<'tcx> {
31 DepNode::Api(id.into_query_param(), args)
32 }
33 pub fn ty(ty: Ty<'tcx>) -> DepNode<'tcx> {
34 DepNode::Ty(TyWrapper::from(ty))
35 }
36 pub fn is_ty(&self) -> bool {
37 matches!(self, DepNode::Ty(_))
38 }
39 pub fn is_api(&self) -> bool {
40 matches!(self, DepNode::Api(..))
41 }
42
43 pub fn as_ty(&self) -> Option<TyWrapper<'tcx>> {
44 match self {
45 DepNode::Ty(ty) => Some(*ty),
46 _ => None,
47 }
48 }
49
50 pub fn expect_ty(&self) -> TyWrapper<'tcx> {
51 match self {
52 DepNode::Ty(ty) => *ty,
53 _ => panic!("{self:?} is not a ty"),
54 }
55 }
56
57 pub fn expect_api(&self) -> (DefId, ty::GenericArgsRef<'tcx>) {
58 match self {
59 DepNode::Api(did, args) => (*did, args),
60 _ => {
61 panic!("{self:?} is not an api")
62 }
63 }
64 }
65}