diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_def/src/item_scope.rs | 41 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/tests/globs.rs | 146 |
2 files changed, 178 insertions, 9 deletions
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs index b03ba939a..571ba3b8a 100644 --- a/crates/ra_hir_def/src/item_scope.rs +++ b/crates/ra_hir_def/src/item_scope.rs | |||
@@ -126,17 +126,40 @@ impl ItemScope { | |||
126 | let mut changed = false; | 126 | let mut changed = false; |
127 | let existing = self.visible.entry(name).or_default(); | 127 | let existing = self.visible.entry(name).or_default(); |
128 | 128 | ||
129 | if existing.types.is_none() && def.types.is_some() { | 129 | match (existing.types, def.types) { |
130 | existing.types = def.types; | 130 | (None, Some(_)) => { |
131 | changed = true; | 131 | existing.types = def.types; |
132 | changed = true; | ||
133 | } | ||
134 | (Some(e), Some(d)) if e.0 != d.0 => { | ||
135 | existing.types = def.types; | ||
136 | changed = true; | ||
137 | } | ||
138 | _ => {} | ||
132 | } | 139 | } |
133 | if existing.values.is_none() && def.values.is_some() { | 140 | |
134 | existing.values = def.values; | 141 | match (existing.values, def.values) { |
135 | changed = true; | 142 | (None, Some(_)) => { |
143 | existing.values = def.values; | ||
144 | changed = true; | ||
145 | } | ||
146 | (Some(e), Some(d)) if e.0 != d.0 => { | ||
147 | existing.values = def.values; | ||
148 | changed = true; | ||
149 | } | ||
150 | _ => {} | ||
136 | } | 151 | } |
137 | if existing.macros.is_none() && def.macros.is_some() { | 152 | |
138 | existing.macros = def.macros; | 153 | match (existing.macros, def.macros) { |
139 | changed = true; | 154 | (None, Some(_)) => { |
155 | existing.macros = def.macros; | ||
156 | changed = true; | ||
157 | } | ||
158 | (Some(e), Some(d)) if e.0 != d.0 => { | ||
159 | existing.macros = def.macros; | ||
160 | changed = true; | ||
161 | } | ||
162 | _ => {} | ||
140 | } | 163 | } |
141 | 164 | ||
142 | changed | 165 | changed |
diff --git a/crates/ra_hir_def/src/nameres/tests/globs.rs b/crates/ra_hir_def/src/nameres/tests/globs.rs index 2b12c0daa..f0d85d301 100644 --- a/crates/ra_hir_def/src/nameres/tests/globs.rs +++ b/crates/ra_hir_def/src/nameres/tests/globs.rs | |||
@@ -229,3 +229,149 @@ fn glob_enum_group() { | |||
229 | "### | 229 | "### |
230 | ); | 230 | ); |
231 | } | 231 | } |
232 | |||
233 | #[test] | ||
234 | fn glob_shadowed_def() { | ||
235 | let db = TestDB::with_files( | ||
236 | r###" | ||
237 | //- /lib.rs | ||
238 | mod foo; | ||
239 | mod bar; | ||
240 | |||
241 | use foo::*; | ||
242 | use bar::Baz; | ||
243 | |||
244 | //- /foo.rs | ||
245 | pub struct Baz; | ||
246 | |||
247 | //- /bar.rs | ||
248 | pub struct Baz; | ||
249 | "###, | ||
250 | ); | ||
251 | let krate = db.test_crate(); | ||
252 | |||
253 | let crate_def_map = db.crate_def_map(krate); | ||
254 | let (_, root_module) = crate_def_map | ||
255 | .modules | ||
256 | .iter() | ||
257 | .find(|(_, module_data)| module_data.parent.is_none()) | ||
258 | .expect("Root module not found"); | ||
259 | let visible_entries = root_module.scope.entries().collect::<Vec<_>>(); | ||
260 | insta::assert_debug_snapshot!( | ||
261 | visible_entries, | ||
262 | @r###" | ||
263 | [ | ||
264 | ( | ||
265 | Name( | ||
266 | Text( | ||
267 | "Baz", | ||
268 | ), | ||
269 | ), | ||
270 | PerNs { | ||
271 | types: Some( | ||
272 | ( | ||
273 | AdtId( | ||
274 | StructId( | ||
275 | StructId( | ||
276 | 1, | ||
277 | ), | ||
278 | ), | ||
279 | ), | ||
280 | Module( | ||
281 | ModuleId { | ||
282 | krate: CrateId( | ||
283 | 0, | ||
284 | ), | ||
285 | local_id: Idx::<ModuleData>(0), | ||
286 | }, | ||
287 | ), | ||
288 | ), | ||
289 | ), | ||
290 | values: Some( | ||
291 | ( | ||
292 | AdtId( | ||
293 | StructId( | ||
294 | StructId( | ||
295 | 1, | ||
296 | ), | ||
297 | ), | ||
298 | ), | ||
299 | Module( | ||
300 | ModuleId { | ||
301 | krate: CrateId( | ||
302 | 0, | ||
303 | ), | ||
304 | local_id: Idx::<ModuleData>(0), | ||
305 | }, | ||
306 | ), | ||
307 | ), | ||
308 | ), | ||
309 | macros: None, | ||
310 | }, | ||
311 | ), | ||
312 | ( | ||
313 | Name( | ||
314 | Text( | ||
315 | "bar", | ||
316 | ), | ||
317 | ), | ||
318 | PerNs { | ||
319 | types: Some( | ||
320 | ( | ||
321 | ModuleId( | ||
322 | ModuleId { | ||
323 | krate: CrateId( | ||
324 | 0, | ||
325 | ), | ||
326 | local_id: Idx::<ModuleData>(2), | ||
327 | }, | ||
328 | ), | ||
329 | Module( | ||
330 | ModuleId { | ||
331 | krate: CrateId( | ||
332 | 0, | ||
333 | ), | ||
334 | local_id: Idx::<ModuleData>(0), | ||
335 | }, | ||
336 | ), | ||
337 | ), | ||
338 | ), | ||
339 | values: None, | ||
340 | macros: None, | ||
341 | }, | ||
342 | ), | ||
343 | ( | ||
344 | Name( | ||
345 | Text( | ||
346 | "foo", | ||
347 | ), | ||
348 | ), | ||
349 | PerNs { | ||
350 | types: Some( | ||
351 | ( | ||
352 | ModuleId( | ||
353 | ModuleId { | ||
354 | krate: CrateId( | ||
355 | 0, | ||
356 | ), | ||
357 | local_id: Idx::<ModuleData>(1), | ||
358 | }, | ||
359 | ), | ||
360 | Module( | ||
361 | ModuleId { | ||
362 | krate: CrateId( | ||
363 | 0, | ||
364 | ), | ||
365 | local_id: Idx::<ModuleData>(0), | ||
366 | }, | ||
367 | ), | ||
368 | ), | ||
369 | ), | ||
370 | values: None, | ||
371 | macros: None, | ||
372 | }, | ||
373 | ), | ||
374 | ] | ||
375 | "### | ||
376 | ); | ||
377 | } | ||