Order of glob imports should not affect import shadowing

This commit is contained in:
Paul Daniel Faria 2020-06-24 09:30:54 -04:00 committed by Paul Daniel Faria
parent 9be0094b5c
commit 70d4829560
2 changed files with 71 additions and 16 deletions

View file

@ -380,26 +380,35 @@ impl DefCollector<'_> {
while self.unresolved_imports.len() < n_previous_unresolved {
n_previous_unresolved = self.unresolved_imports.len();
let imports = std::mem::replace(&mut self.unresolved_imports, Vec::new());
for mut directive in imports {
let mut imports = std::mem::replace(&mut self.unresolved_imports, Vec::new());
for mut directive in &mut imports {
directive.status = self.resolve_import(directive.module_id, &directive.import);
}
match directive.status {
PartialResolvedImport::Indeterminate(_) => {
self.record_resolved_import(&directive);
// FIXME: For avoid performance regression,
// we consider an imported resolved if it is indeterminate (i.e not all namespace resolved)
self.resolved_imports.push(directive)
}
PartialResolvedImport::Resolved(_) => {
self.record_resolved_import(&directive);
self.resolved_imports.push(directive)
}
PartialResolvedImport::Unresolved => {
self.unresolved_imports.push(directive);
let (glob_imports, non_glob_imports): (Vec<_>, Vec<_>) =
imports.into_iter().partition(|directive| directive.import.is_glob);
let mut record = |imports: Vec<ImportDirective>| {
for directive in imports {
match directive.status {
PartialResolvedImport::Indeterminate(_) => {
self.record_resolved_import(&directive);
// FIXME: For avoid performance regression,
// we consider an imported resolved if it is indeterminate (i.e not all namespace resolved)
self.resolved_imports.push(directive)
}
PartialResolvedImport::Resolved(_) => {
self.record_resolved_import(&directive);
self.resolved_imports.push(directive)
}
PartialResolvedImport::Unresolved => {
self.unresolved_imports.push(directive);
}
}
}
}
};
record(glob_imports);
record(non_glob_imports);
}
}

View file

@ -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
"###
);
}