From 70d4829560b81e3f5dc8e624da702ed6d345c49c Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Wed, 24 Jun 2020 09:30:54 -0400 Subject: Order of glob imports should not affect import shadowing --- crates/ra_hir_def/src/nameres/collector.rs | 41 +++++++++++++++---------- crates/ra_hir_def/src/nameres/tests/globs.rs | 46 ++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 16 deletions(-) (limited to 'crates/ra_hir_def/src/nameres') diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 94da700ad..665dd106c 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -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| { + 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); } } diff --git a/crates/ra_hir_def/src/nameres/tests/globs.rs b/crates/ra_hir_def/src/nameres/tests/globs.rs index 2f440975a..d5a02137c 100644 --- a/crates/ra_hir_def/src/nameres/tests/globs.rs +++ b/crates/ra_hir_def/src/nameres/tests/globs.rs @@ -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 + "### + ); +} -- cgit v1.2.3