diff options
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r-- | crates/ra_hir/src/ty/method_resolution.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/crates/ra_hir/src/ty/method_resolution.rs b/crates/ra_hir/src/ty/method_resolution.rs index 080ba1ef6..e023ff25a 100644 --- a/crates/ra_hir/src/ty/method_resolution.rs +++ b/crates/ra_hir/src/ty/method_resolution.rs | |||
@@ -115,6 +115,8 @@ impl CrateImplBlocks { | |||
115 | } | 115 | } |
116 | 116 | ||
117 | fn def_crates(db: &impl HirDatabase, cur_crate: Crate, ty: &Ty) -> Option<ArrayVec<[Crate; 2]>> { | 117 | fn def_crates(db: &impl HirDatabase, cur_crate: Crate, ty: &Ty) -> Option<ArrayVec<[Crate; 2]>> { |
118 | // Types like slice can have inherent impls in several crates, (core and alloc). | ||
119 | // The correspoinding impls are marked with lang items, so we can use them to find the required crates. | ||
118 | macro_rules! lang_item_crate { | 120 | macro_rules! lang_item_crate { |
119 | ($db:expr, $cur_crate:expr, $($name:expr),+ $(,)?) => {{ | 121 | ($db:expr, $cur_crate:expr, $($name:expr),+ $(,)?) => {{ |
120 | let mut v = ArrayVec::<[Crate; 2]>::new(); | 122 | let mut v = ArrayVec::<[Crate; 2]>::new(); |
@@ -128,16 +130,16 @@ fn def_crates(db: &impl HirDatabase, cur_crate: Crate, ty: &Ty) -> Option<ArrayV | |||
128 | match ty { | 130 | match ty { |
129 | Ty::Apply(a_ty) => match a_ty.ctor { | 131 | Ty::Apply(a_ty) => match a_ty.ctor { |
130 | TypeCtor::Adt(def_id) => Some(std::iter::once(def_id.krate(db)?).collect()), | 132 | TypeCtor::Adt(def_id) => Some(std::iter::once(def_id.krate(db)?).collect()), |
131 | TypeCtor::Bool => lang_item_crate![db, cur_crate, "bool"], | 133 | TypeCtor::Bool => lang_item_crate!(db, cur_crate, "bool"), |
132 | TypeCtor::Char => lang_item_crate![db, cur_crate, "char"], | 134 | TypeCtor::Char => lang_item_crate!(db, cur_crate, "char"), |
133 | TypeCtor::Float(UncertainFloatTy::Known(f)) => { | 135 | TypeCtor::Float(UncertainFloatTy::Known(f)) => { |
134 | lang_item_crate![db, cur_crate, f.ty_to_string()] | 136 | lang_item_crate!(db, cur_crate, f.ty_to_string()) |
135 | } | 137 | } |
136 | TypeCtor::Int(UncertainIntTy::Known(i)) => { | 138 | TypeCtor::Int(UncertainIntTy::Known(i)) => { |
137 | lang_item_crate![db, cur_crate, i.ty_to_string()] | 139 | lang_item_crate!(db, cur_crate, i.ty_to_string()) |
138 | } | 140 | } |
139 | TypeCtor::Str => lang_item_crate![db, cur_crate, "str"], | 141 | TypeCtor::Str => lang_item_crate!(db, cur_crate, "str"), |
140 | TypeCtor::Slice => lang_item_crate![db, cur_crate, "slice_alloc", "slice"], | 142 | TypeCtor::Slice => lang_item_crate!(db, cur_crate, "slice_alloc", "slice"), |
141 | _ => None, | 143 | _ => None, |
142 | }, | 144 | }, |
143 | _ => None, | 145 | _ => None, |