diff options
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r-- | crates/ra_hir_def/src/item_scope.rs | 31 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/tests/globs.rs | 47 |
2 files changed, 67 insertions, 11 deletions
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs index b03ba939a..c81b966c3 100644 --- a/crates/ra_hir_def/src/item_scope.rs +++ b/crates/ra_hir_def/src/item_scope.rs | |||
@@ -5,6 +5,7 @@ use hir_expand::name::Name; | |||
5 | use once_cell::sync::Lazy; | 5 | use once_cell::sync::Lazy; |
6 | use ra_db::CrateId; | 6 | use ra_db::CrateId; |
7 | use rustc_hash::FxHashMap; | 7 | use rustc_hash::FxHashMap; |
8 | use test_utils::mark; | ||
8 | 9 | ||
9 | use crate::{ | 10 | use crate::{ |
10 | db::DefDatabase, per_ns::PerNs, visibility::Visibility, AdtId, BuiltinType, HasModule, ImplId, | 11 | db::DefDatabase, per_ns::PerNs, visibility::Visibility, AdtId, BuiltinType, HasModule, ImplId, |
@@ -126,19 +127,27 @@ impl ItemScope { | |||
126 | let mut changed = false; | 127 | let mut changed = false; |
127 | let existing = self.visible.entry(name).or_default(); | 128 | let existing = self.visible.entry(name).or_default(); |
128 | 129 | ||
129 | if existing.types.is_none() && def.types.is_some() { | 130 | macro_rules! check_changed { |
130 | existing.types = def.types; | 131 | ($changed:ident, $existing:expr, $def:expr) => { |
131 | changed = true; | 132 | match ($existing, $def) { |
132 | } | 133 | (None, Some(_)) => { |
133 | if existing.values.is_none() && def.values.is_some() { | 134 | $existing = $def; |
134 | existing.values = def.values; | 135 | $changed = true; |
135 | changed = true; | 136 | } |
136 | } | 137 | (Some(e), Some(d)) if e.0 != d.0 => { |
137 | if existing.macros.is_none() && def.macros.is_some() { | 138 | mark::hit!(import_shadowed); |
138 | existing.macros = def.macros; | 139 | $existing = $def; |
139 | changed = true; | 140 | $changed = true; |
141 | } | ||
142 | _ => {} | ||
143 | } | ||
144 | }; | ||
140 | } | 145 | } |
141 | 146 | ||
147 | check_changed!(changed, existing.types, def.types); | ||
148 | check_changed!(changed, existing.values, def.values); | ||
149 | check_changed!(changed, existing.macros, def.macros); | ||
150 | |||
142 | changed | 151 | changed |
143 | } | 152 | } |
144 | 153 | ||
diff --git a/crates/ra_hir_def/src/nameres/tests/globs.rs b/crates/ra_hir_def/src/nameres/tests/globs.rs index 2b12c0daa..2f440975a 100644 --- a/crates/ra_hir_def/src/nameres/tests/globs.rs +++ b/crates/ra_hir_def/src/nameres/tests/globs.rs | |||
@@ -229,3 +229,50 @@ fn glob_enum_group() { | |||
229 | "### | 229 | "### |
230 | ); | 230 | ); |
231 | } | 231 | } |
232 | |||
233 | #[test] | ||
234 | fn glob_shadowed_def() { | ||
235 | mark::check!(import_shadowed); | ||
236 | let map = def_map( | ||
237 | r###" | ||
238 | //- /lib.rs | ||
239 | mod foo; | ||
240 | mod bar; | ||
241 | |||
242 | use foo::*; | ||
243 | use bar::baz; | ||
244 | |||
245 | use baz::Bar; | ||
246 | |||
247 | //- /foo.rs | ||
248 | pub mod baz { | ||
249 | pub struct Foo; | ||
250 | } | ||
251 | |||
252 | //- /bar.rs | ||
253 | pub mod baz { | ||
254 | pub struct Bar; | ||
255 | } | ||
256 | "###, | ||
257 | ); | ||
258 | assert_snapshot!(map, @r###" | ||
259 | ⋮crate | ||
260 | ⋮Bar: t v | ||
261 | ⋮bar: t | ||
262 | ⋮baz: t | ||
263 | ⋮foo: t | ||
264 | ⋮ | ||
265 | ⋮crate::bar | ||
266 | ⋮baz: t | ||
267 | ⋮ | ||
268 | ⋮crate::bar::baz | ||
269 | ⋮Bar: t v | ||
270 | ⋮ | ||
271 | ⋮crate::foo | ||
272 | ⋮baz: t | ||
273 | ⋮ | ||
274 | ⋮crate::foo::baz | ||
275 | ⋮Foo: t v | ||
276 | "### | ||
277 | ); | ||
278 | } | ||