Check ancestor maps when computing traits in scope
This commit is contained in:
parent
6be4f30cae
commit
12f6bdcfd9
@ -342,6 +342,16 @@ pub fn traits_in_scope(&self, db: &dyn DefDatabase) -> FxHashSet<TraitId> {
|
||||
traits.extend(prelude_def_map[prelude.local_id].scope.traits());
|
||||
}
|
||||
traits.extend(m.def_map[m.module_id].scope.traits());
|
||||
|
||||
// Add all traits that are in scope because of the containing DefMaps
|
||||
m.def_map.with_ancestor_maps(db, m.module_id, &mut |def_map, module| {
|
||||
if let Some(prelude) = def_map.prelude() {
|
||||
let prelude_def_map = prelude.def_map(db);
|
||||
traits.extend(prelude_def_map[prelude.local_id].scope.traits());
|
||||
}
|
||||
traits.extend(def_map[module].scope.traits());
|
||||
None::<()>
|
||||
});
|
||||
}
|
||||
}
|
||||
traits
|
||||
|
@ -3173,6 +3173,39 @@ fn f() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trait_in_scope_with_inner_item() {
|
||||
check_infer(
|
||||
r#"
|
||||
mod m {
|
||||
pub trait Tr {
|
||||
fn method(&self) -> u8 { 0 }
|
||||
}
|
||||
|
||||
impl Tr for () {}
|
||||
}
|
||||
|
||||
use m::Tr;
|
||||
|
||||
fn f() {
|
||||
fn inner() {
|
||||
().method();
|
||||
//^^^^^^^^^^^ u8
|
||||
}
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
46..50 'self': &Self
|
||||
58..63 '{ 0 }': u8
|
||||
60..61 '0': u8
|
||||
115..185 '{ ... } }': ()
|
||||
132..183 '{ ... }': ()
|
||||
142..144 '()': ()
|
||||
142..153 '().method()': u8
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inner_use_in_block() {
|
||||
check_types(
|
||||
|
Loading…
Reference in New Issue
Block a user