mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Order of glob imports should not affect import shadowing
This commit is contained in:
parent
9be0094b5c
commit
70d4829560
2 changed files with 71 additions and 16 deletions
|
@ -380,26 +380,35 @@ impl DefCollector<'_> {
|
||||||
|
|
||||||
while self.unresolved_imports.len() < n_previous_unresolved {
|
while self.unresolved_imports.len() < n_previous_unresolved {
|
||||||
n_previous_unresolved = self.unresolved_imports.len();
|
n_previous_unresolved = self.unresolved_imports.len();
|
||||||
let imports = std::mem::replace(&mut self.unresolved_imports, Vec::new());
|
let mut imports = std::mem::replace(&mut self.unresolved_imports, Vec::new());
|
||||||
for mut directive in imports {
|
for mut directive in &mut imports {
|
||||||
directive.status = self.resolve_import(directive.module_id, &directive.import);
|
directive.status = self.resolve_import(directive.module_id, &directive.import);
|
||||||
|
}
|
||||||
|
|
||||||
match directive.status {
|
let (glob_imports, non_glob_imports): (Vec<_>, Vec<_>) =
|
||||||
PartialResolvedImport::Indeterminate(_) => {
|
imports.into_iter().partition(|directive| directive.import.is_glob);
|
||||||
self.record_resolved_import(&directive);
|
let mut record = |imports: Vec<ImportDirective>| {
|
||||||
// FIXME: For avoid performance regression,
|
for directive in imports {
|
||||||
// we consider an imported resolved if it is indeterminate (i.e not all namespace resolved)
|
match directive.status {
|
||||||
self.resolved_imports.push(directive)
|
PartialResolvedImport::Indeterminate(_) => {
|
||||||
}
|
self.record_resolved_import(&directive);
|
||||||
PartialResolvedImport::Resolved(_) => {
|
// FIXME: For avoid performance regression,
|
||||||
self.record_resolved_import(&directive);
|
// we consider an imported resolved if it is indeterminate (i.e not all namespace resolved)
|
||||||
self.resolved_imports.push(directive)
|
self.resolved_imports.push(directive)
|
||||||
}
|
}
|
||||||
PartialResolvedImport::Unresolved => {
|
PartialResolvedImport::Resolved(_) => {
|
||||||
self.unresolved_imports.push(directive);
|
self.record_resolved_import(&directive);
|
||||||
|
self.resolved_imports.push(directive)
|
||||||
|
}
|
||||||
|
PartialResolvedImport::Unresolved => {
|
||||||
|
self.unresolved_imports.push(directive);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
record(glob_imports);
|
||||||
|
record(non_glob_imports);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -276,3 +276,49 @@ fn glob_shadowed_def() {
|
||||||
"###
|
"###
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn glob_shadowed_def_reversed() {
|
||||||
|
let map = def_map(
|
||||||
|
r###"
|
||||||
|
//- /lib.rs
|
||||||
|
mod foo;
|
||||||
|
mod bar;
|
||||||
|
|
||||||
|
use bar::baz;
|
||||||
|
use foo::*;
|
||||||
|
|
||||||
|
use baz::Bar;
|
||||||
|
|
||||||
|
//- /foo.rs
|
||||||
|
pub mod baz {
|
||||||
|
pub struct Foo;
|
||||||
|
}
|
||||||
|
|
||||||
|
//- /bar.rs
|
||||||
|
pub mod baz {
|
||||||
|
pub struct Bar;
|
||||||
|
}
|
||||||
|
"###,
|
||||||
|
);
|
||||||
|
assert_snapshot!(map, @r###"
|
||||||
|
⋮crate
|
||||||
|
⋮Bar: t v
|
||||||
|
⋮bar: t
|
||||||
|
⋮baz: t
|
||||||
|
⋮foo: t
|
||||||
|
⋮
|
||||||
|
⋮crate::bar
|
||||||
|
⋮baz: t
|
||||||
|
⋮
|
||||||
|
⋮crate::bar::baz
|
||||||
|
⋮Bar: t v
|
||||||
|
⋮
|
||||||
|
⋮crate::foo
|
||||||
|
⋮baz: t
|
||||||
|
⋮
|
||||||
|
⋮crate::foo::baz
|
||||||
|
⋮Foo: t v
|
||||||
|
"###
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue