Skip to content

Commit ba26af3

Browse files
authored
Rollup merge of #126568 - bvanjoi:fix-126376, r=petrochenkov
mark undetermined if target binding in current ns is not got Fixes #126376 Fixes #126389 Add a branch to handle more cases... r? `@petrochenkov`
2 parents 3baa20b + 2f17535 commit ba26af3

7 files changed

+101
-38
lines changed

Diff for: compiler/rustc_resolve/src/ident.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
966966
for single_import in &resolution.single_imports {
967967
let Some(import_vis) = single_import.vis.get() else {
968968
// This branch handles a cycle in single imports, which occurs
969-
// when we've previously captured the `vis` value during an import
969+
// when we've previously **steal** the `vis` value during an import
970970
// process.
971971
//
972972
// For example:
@@ -998,21 +998,28 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
998998
let Some(module) = single_import.imported_module.get() else {
999999
return Err((Undetermined, Weak::No));
10001000
};
1001-
let ImportKind::Single { source: ident, target, target_bindings, .. } =
1002-
&single_import.kind
1001+
let ImportKind::Single { source, target, target_bindings, .. } = &single_import.kind
10031002
else {
10041003
unreachable!();
10051004
};
1006-
if (ident != target) && target_bindings.iter().all(|binding| binding.get().is_none()) {
1005+
if source != target {
10071006
// This branch allows the binding to be defined or updated later if the target name
1008-
// can hide the source but these bindings are not obtained.
1009-
// avoiding module inconsistency between the resolve process and the finalize process.
1010-
// See more details in #124840
1011-
return Err((Undetermined, Weak::No));
1007+
// can hide the source.
1008+
if target_bindings.iter().all(|binding| binding.get().is_none()) {
1009+
// None of the target bindings are available, so we can't determine
1010+
// if this binding is correct or not.
1011+
// See more details in #124840
1012+
return Err((Undetermined, Weak::No));
1013+
} else if target_bindings[ns].get().is_none() && binding.is_some() {
1014+
// `binding.is_some()` avoids the condition where the binding
1015+
// truly doesn't exist in this namespace and should return `Err(Determined)`.
1016+
return Err((Undetermined, Weak::No));
1017+
}
10121018
}
1019+
10131020
match self.resolve_ident_in_module(
10141021
module,
1015-
*ident,
1022+
*source,
10161023
ns,
10171024
&single_import.parent_scope,
10181025
None,

Diff for: tests/crashes/126376.rs

-14
This file was deleted.

Diff for: tests/crashes/126389.rs

-15
This file was deleted.

Diff for: tests/ui/imports/shadow-glob-module-resolution-3.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// https://github.com/rust-lang/rust/issues/126389
2+
3+
mod a {
4+
pub mod b {
5+
pub mod c {}
6+
}
7+
}
8+
9+
use a::*;
10+
11+
use b::c;
12+
//~^ ERROR: unresolved import `b::c`
13+
//~| ERROR: cannot determine resolution for the import
14+
//~| ERROR: cannot determine resolution for the import
15+
use c as b;
16+
17+
fn c() {}
18+
19+
fn main() { }
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error: cannot determine resolution for the import
2+
--> $DIR/shadow-glob-module-resolution-3.rs:11:5
3+
|
4+
LL | use b::c;
5+
| ^^^^
6+
7+
error: cannot determine resolution for the import
8+
--> $DIR/shadow-glob-module-resolution-3.rs:11:5
9+
|
10+
LL | use b::c;
11+
| ^^^^
12+
|
13+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
14+
15+
error[E0432]: unresolved import `b::c`
16+
--> $DIR/shadow-glob-module-resolution-3.rs:11:5
17+
|
18+
LL | use b::c;
19+
| ^^^^
20+
21+
error: aborting due to 3 previous errors
22+
23+
For more information about this error, try `rustc --explain E0432`.

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

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// https://github.com/rust-lang/rust/issues/126376
2+
3+
mod a {
4+
pub mod b {
5+
pub trait C {}
6+
}
7+
}
8+
9+
use a::*;
10+
11+
use e as b;
12+
13+
use b::C as e;
14+
//~^ ERROR: unresolved import `b::C`
15+
//~| ERROR: cannot determine resolution for the import
16+
//~| ERROR: cannot determine resolution for the import
17+
18+
fn e() {}
19+
20+
fn main() { }
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
15+
error[E0432]: unresolved import `b::C`
16+
--> $DIR/shadow-glob-module-resolution-4.rs:13:5
17+
|
18+
LL | use b::C as e;
19+
| ^^^^^^^^^
20+
21+
error: aborting due to 3 previous errors
22+
23+
For more information about this error, try `rustc --explain E0432`.

0 commit comments

Comments
 (0)