Skip to content

Commit 9b1c304

Browse files
committed
mark binding undetermined if target name exist and not obtained
1 parent 2b6a342 commit 9b1c304

File tree

5 files changed

+51
-5
lines changed

5 files changed

+51
-5
lines changed

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -998,14 +998,14 @@ 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, source_bindings, .. } = &single_import.kind
1001+
let ImportKind::Single { source: ident, target, target_bindings, .. } =
1002+
&single_import.kind
10021003
else {
10031004
unreachable!();
10041005
};
1005-
if binding.map_or(false, |binding| binding.module().is_some())
1006-
&& source_bindings.iter().all(|binding| matches!(binding.get(), Err(Undetermined)))
1007-
{
1008-
// This branch allows the binding to be defined or updated later,
1006+
if (ident != target) && target_bindings.iter().all(|binding| binding.get().is_none()) {
1007+
// 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.
10091009
// avoiding module inconsistency between the resolve process and the finalize process.
10101010
// See more details in #124840
10111011
return Err((Undetermined, Weak::No));

Diff for: tests/ui/imports/cycle-import-in-std-1.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ edition: 2018
2+
3+
// https://github.com./rust-lang/rust/issues/124490
4+
5+
use io::{self as std};
6+
//~^ ERROR: unresolved import `io`
7+
use std::collections::{self as io};
8+
9+
fn main() {}

Diff for: tests/ui/imports/cycle-import-in-std-1.stderr

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0432]: unresolved import `io`
2+
--> $DIR/cycle-import-in-std-1.rs:5:10
3+
|
4+
LL | use io::{self as std};
5+
| ^^^^^^^^^^^ no external crate `io`
6+
|
7+
= help: consider importing one of these items instead:
8+
core::io
9+
std::io
10+
std::os::unix::io
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0432`.

Diff for: tests/ui/imports/cycle-import-in-std-2.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ edition: 2018
2+
3+
// https://github.com./rust-lang/rust/issues/125013
4+
5+
use io::{self as std};
6+
//~^ ERROR: unresolved import `io`
7+
use std::ops::Deref::{self as io};
8+
9+
fn main() {}

Diff for: tests/ui/imports/cycle-import-in-std-2.stderr

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0432]: unresolved import `io`
2+
--> $DIR/cycle-import-in-std-2.rs:5:10
3+
|
4+
LL | use io::{self as std};
5+
| ^^^^^^^^^^^ no external crate `io`
6+
|
7+
= help: consider importing one of these items instead:
8+
core::io
9+
std::io
10+
std::os::unix::io
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0432`.

0 commit comments

Comments
 (0)