Skip to content

Commit 9668737

Browse files
committed
Add comment
1 parent 9e7a6bd commit 9668737

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

crates/ra_hir/src/ty/method_resolution.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ impl CrateImplBlocks {
115115
}
116116

117117
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.
118120
macro_rules! lang_item_crate {
119121
($db:expr, $cur_crate:expr, $($name:expr),+ $(,)?) => {{
120122
let mut v = ArrayVec::<[Crate; 2]>::new();
@@ -128,16 +130,16 @@ fn def_crates(db: &impl HirDatabase, cur_crate: Crate, ty: &Ty) -> Option<ArrayV
128130
match ty {
129131
Ty::Apply(a_ty) => match a_ty.ctor {
130132
TypeCtor::Adt(def_id) => Some(std::iter::once(def_id.krate(db)?).collect()),
131-
TypeCtor::Bool => lang_item_crate![db, cur_crate, "bool"],
132-
TypeCtor::Char => lang_item_crate![db, cur_crate, "char"],
133+
TypeCtor::Bool => lang_item_crate!(db, cur_crate, "bool"),
134+
TypeCtor::Char => lang_item_crate!(db, cur_crate, "char"),
133135
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())
135137
}
136138
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())
138140
}
139-
TypeCtor::Str => lang_item_crate![db, cur_crate, "str"],
140-
TypeCtor::Slice => lang_item_crate![db, cur_crate, "slice_alloc", "slice"],
141+
TypeCtor::Str => lang_item_crate!(db, cur_crate, "str"),
142+
TypeCtor::Slice => lang_item_crate!(db, cur_crate, "slice_alloc", "slice"),
141143
_ => None,
142144
},
143145
_ => None,

0 commit comments

Comments
 (0)