rapx/analysis/core/api_dep/graph/
dep_node.rs1use std::hash::Hash;
2
3use super::ty_wrapper::TyWrapper;
4use rustc_middle::{
5 query::IntoQueryParam,
6 ty::{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(Clone, Debug, Eq, PartialEq, Hash)]
17pub enum DepNode<'tcx> {
18 Api(DefId),
19 Ty(TyWrapper<'tcx>),
20 GenericParamDef(DefId, usize, String, bool), }
22
23pub fn desc_str<'tcx>(node: DepNode<'tcx>, tcx: TyCtxt<'tcx>) -> String {
24 match node {
25 DepNode::Api(def_id) => tcx.def_path_str(def_id),
26 DepNode::Ty(ty) => ty.desc_str(tcx),
27 DepNode::GenericParamDef(idx, index, sym, is_lifetime) => {
28 format!("{sym}/#{index}")
29 }
30 }
31}
32
33impl<'tcx> DepNode<'tcx> {
34 pub fn api(id: impl IntoQueryParam<DefId>) -> DepNode<'tcx> {
35 DepNode::Api(id.into_query_param())
36 }
37 pub fn ty(ty: Ty<'tcx>) -> DepNode<'tcx> {
38 DepNode::Ty(TyWrapper::from(ty))
39 }
40 pub fn generic_param_def(
41 fn_def_id: DefId,
42 index: usize,
43 name: impl ToString,
44 is_lifetime: bool,
45 ) -> DepNode<'tcx> {
46 DepNode::GenericParamDef(fn_def_id, index, name.to_string(), is_lifetime)
47 }
48}