aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def
diff options
context:
space:
mode:
authorPaul Daniel Faria <[email protected]>2020-06-24 14:30:54 +0100
committerPaul Daniel Faria <[email protected]>2020-06-25 14:23:34 +0100
commit70d4829560b81e3f5dc8e624da702ed6d345c49c (patch)
tree2757e7221b3955e4a2016717ef49280a5557a3c7 /crates/ra_hir_def
parent9be0094b5cc24d82541d98a7bd00187c18388fd3 (diff)
Order of glob imports should not affect import shadowing
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs41
-rw-r--r--crates/ra_hir_def/src/nameres/tests/globs.rs46
2 files changed, 71 insertions, 16 deletions
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<'_> {
380 380
381 while self.unresolved_imports.len() < n_previous_unresolved { 381 while self.unresolved_imports.len() < n_previous_unresolved {
382 n_previous_unresolved = self.unresolved_imports.len(); 382 n_previous_unresolved = self.unresolved_imports.len();
383 let imports = std::mem::replace(&mut self.unresolved_imports, Vec::new()); 383 let mut imports = std::mem::replace(&mut self.unresolved_imports, Vec::new());
384 for mut directive in imports { 384 for mut directive in &mut imports {
385 directive.status = self.resolve_import(directive.module_id, &directive.import); 385 directive.status = self.resolve_import(directive.module_id, &directive.import);
386 }
386 387
387 match directive.status { 388 let (glob_imports, non_glob_imports): (Vec<_>, Vec<_>) =
388 PartialResolvedImport::Indeterminate(_) => { 389 imports.into_iter().partition(|directive| directive.import.is_glob);
389 self.record_resolved_import(&directive); 390 let mut record = |imports: Vec<ImportDirective>| {
390 // FIXME: For avoid performance regression, 391 for directive in imports {
391 // we consider an imported resolved if it is indeterminate (i.e not all namespace resolved) 392 match directive.status {
392 self.resolved_imports.push(directive) 393 PartialResolvedImport::Indeterminate(_) => {
393 } 394 self.record_resolved_import(&directive);
394 PartialResolvedImport::Resolved(_) => { 395 // FIXME: For avoid performance regression,
395 self.record_resolved_import(&directive); 396 // we consider an imported resolved if it is indeterminate (i.e not all namespace resolved)
396 self.resolved_imports.push(directive) 397 self.resolved_imports.push(directive)
397 } 398 }
398 PartialResolvedImport::Unresolved => { 399 PartialResolvedImport::Resolved(_) => {
399 self.unresolved_imports.push(directive); 400 self.record_resolved_import(&directive);
401 self.resolved_imports.push(directive)
402 }
403 PartialResolvedImport::Unresolved => {
404 self.unresolved_imports.push(directive);
405 }
400 } 406 }
401 } 407 }
402 } 408 };
409
410 record(glob_imports);
411 record(non_glob_imports);
403 } 412 }
404 } 413 }
405 414
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() {
276 "### 276 "###
277 ); 277 );
278} 278}
279
280#[test]
281fn glob_shadowed_def_reversed() {
282 let map = def_map(
283 r###"
284 //- /lib.rs
285 mod foo;
286 mod bar;
287
288 use bar::baz;
289 use foo::*;
290
291 use baz::Bar;
292
293 //- /foo.rs
294 pub mod baz {
295 pub struct Foo;
296 }
297
298 //- /bar.rs
299 pub mod baz {
300 pub struct Bar;
301 }
302 "###,
303 );
304 assert_snapshot!(map, @r###"
305 ⋮crate
306 ⋮Bar: t v
307 ⋮bar: t
308 ⋮baz: t
309 ⋮foo: t
310
311 ⋮crate::bar
312 ⋮baz: t
313
314 ⋮crate::bar::baz
315 ⋮Bar: t v
316
317 ⋮crate::foo
318 ⋮baz: t
319
320 ⋮crate::foo::baz
321 ⋮Foo: t v
322 "###
323 );
324}