Skip to content

Commit b0b1ebe

Browse files
committed
resolve: Remove a special case for dummy imports
It is no longer needed to pass import validation, and the removal avoids some secondary errors. Also add a couple of asserts
1 parent 7559c2c commit b0b1ebe

7 files changed

Lines changed: 11 additions & 64 deletions

compiler/rustc_resolve/src/imports.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -456,13 +456,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
456456
warn_ambiguity,
457457
|this, resolution| {
458458
assert!(!decl.warn_ambiguity.get());
459-
if res == Res::Err
460-
&& let Some(old_decl) = resolution.best_decl()
461-
&& old_decl.res() != Res::Err
462-
{
463-
// Do not override real declarations with `Res::Err`s from error recovery.
464-
return Ok(());
465-
}
466459
if decl.is_glob_import() {
467460
resolution.glob_decl = Some(match resolution.glob_decl {
468461
Some(old_decl) => this.select_glob_decl(
@@ -533,13 +526,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
533526
};
534527
if self.is_accessible_from(binding.vis(), scope) {
535528
let import_decl = self.new_import_decl(binding, *import);
536-
let _ = self.try_plant_decl_into_local_module(
529+
self.try_plant_decl_into_local_module(
537530
ident,
538531
orig_ident_span,
539532
key.ns,
540533
import_decl,
541534
warn_ambiguity,
542-
);
535+
)
536+
.expect("planting a glob cannot fail");
543537
}
544538
}
545539

@@ -558,6 +552,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
558552
self.per_ns(|this, ns| {
559553
let module = import.parent_scope.module;
560554
let ident = IdentKey::new(target);
555+
// This can fail, dummies are inserted only in non-occupied slots.
561556
let _ = this.try_plant_decl_into_local_module(
562557
ident,
563558
target.span,
@@ -1613,13 +1608,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16131608
.resolution(import.parent_scope.module, key)
16141609
.and_then(|r| r.determined_decl())
16151610
.is_some_and(|binding| binding.warn_ambiguity_recursive());
1616-
let _ = self.try_plant_decl_into_local_module(
1611+
self.try_plant_decl_into_local_module(
16171612
key.ident,
16181613
orig_ident_span,
16191614
key.ns,
16201615
import_decl,
16211616
warn_ambiguity,
1622-
);
1617+
)
1618+
.expect("planting a glob cannot fail");
16231619
}
16241620
}
16251621

tests/ui/imports/issue-56125.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod m2 {
1515
mod m3 {
1616
mod empty {}
1717
use empty::issue_56125; //~ ERROR unresolved import `empty::issue_56125`
18-
use issue_56125::*; //~ ERROR `issue_56125` is ambiguous
18+
use issue_56125::*;
1919
}
2020

2121
fn main() {}

tests/ui/imports/issue-56125.stderr

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,7 @@ LL | use issue_56125::non_last_segment::non_last_segment::*;
5454
= help: consider adding an explicit import of `issue_56125` to disambiguate
5555
= help: or use `self::issue_56125` to refer to this module unambiguously
5656

57-
error[E0659]: `issue_56125` is ambiguous
58-
--> $DIR/issue-56125.rs:18:9
59-
|
60-
LL | use issue_56125::*;
61-
| ^^^^^^^^^^^ ambiguous name
62-
|
63-
= note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution
64-
= note: `issue_56125` could refer to a crate passed with `--extern`
65-
= help: use `::issue_56125` to refer to this crate unambiguously
66-
note: `issue_56125` could also refer to the module imported here
67-
--> $DIR/issue-56125.rs:18:9
68-
|
69-
LL | use issue_56125::*;
70-
| ^^^^^^^^^^^^^^
71-
= help: consider adding an explicit import of `issue_56125` to disambiguate
72-
= help: or use `self::issue_56125` to refer to this module unambiguously
73-
74-
error: aborting due to 4 previous errors
57+
error: aborting due to 3 previous errors
7558

7659
Some errors have detailed explanations: E0432, E0659.
7760
For more information about an error, try `rustc --explain E0432`.

tests/ui/imports/shadow-glob-module-resolution-2.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,5 @@ use a::*;
1414
use e as b;
1515
//~^ ERROR: unresolved import `e`
1616
use b::c::D as e;
17-
//~^ ERROR: cannot determine resolution for the import
18-
//~| ERROR: cannot determine resolution for the import
1917

2018
fn main() { }
Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
error: cannot determine resolution for the import
2-
--> $DIR/shadow-glob-module-resolution-2.rs:16:5
3-
|
4-
LL | use b::c::D as e;
5-
| ^^^^^^^^^^^^
6-
7-
error: cannot determine resolution for the import
8-
--> $DIR/shadow-glob-module-resolution-2.rs:16:5
9-
|
10-
LL | use b::c::D as e;
11-
| ^^^^^^^^^^^^
12-
|
13-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
14-
151
error[E0432]: unresolved import `e`
162
--> $DIR/shadow-glob-module-resolution-2.rs:14:5
173
|
@@ -24,6 +10,6 @@ LL - use e as b;
2410
LL + use a as b;
2511
|
2612

27-
error: aborting due to 3 previous errors
13+
error: aborting due to 1 previous error
2814

2915
For more information about this error, try `rustc --explain E0432`.

tests/ui/imports/shadow-glob-module-resolution-4.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ use e as b;
1212

1313
use b::C as e;
1414
//~^ ERROR: unresolved import `b::C`
15-
//~| ERROR: cannot determine resolution for the import
16-
//~| ERROR: cannot determine resolution for the import
1715

1816
fn e() {}
1917

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,9 @@
1-
error: cannot determine resolution for the import
2-
--> $DIR/shadow-glob-module-resolution-4.rs:13:5
3-
|
4-
LL | use b::C as e;
5-
| ^^^^^^^^^
6-
7-
error: cannot determine resolution for the import
8-
--> $DIR/shadow-glob-module-resolution-4.rs:13:5
9-
|
10-
LL | use b::C as e;
11-
| ^^^^^^^^^
12-
|
13-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
14-
151
error[E0432]: unresolved import `b::C`
162
--> $DIR/shadow-glob-module-resolution-4.rs:13:5
173
|
184
LL | use b::C as e;
195
| ^^^^^^^^^
206

21-
error: aborting due to 3 previous errors
7+
error: aborting due to 1 previous error
228

239
For more information about this error, try `rustc --explain E0432`.

0 commit comments

Comments
 (0)