Skip to content

Commit

Permalink
Rollup merge of rust-lang#126065 - bvanjoi:fix-124490, r=petrochenkov
Browse files Browse the repository at this point in the history
mark binding undetermined if target name exist and not obtained

- Fixes rust-lang#124490
- Fixes rust-lang#125013

Following up on rust-lang#124840, I think handling only `target_bindings` is sufficient.

r? `@petrochenkov`
  • Loading branch information
workingjubilee authored Jun 7, 2024
2 parents cfb9479 + 9b1c304 commit 713b9fa
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
10 changes: 5 additions & 5 deletions compiler/rustc_resolve/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,14 +998,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
let Some(module) = single_import.imported_module.get() else {
return Err((Undetermined, Weak::No));
};
let ImportKind::Single { source: ident, source_bindings, .. } = &single_import.kind
let ImportKind::Single { source: ident, target, target_bindings, .. } =
&single_import.kind
else {
unreachable!();
};
if binding.map_or(false, |binding| binding.module().is_some())
&& source_bindings.iter().all(|binding| matches!(binding.get(), Err(Undetermined)))
{
// This branch allows the binding to be defined or updated later,
if (ident != target) && target_bindings.iter().all(|binding| binding.get().is_none()) {
// This branch allows the binding to be defined or updated later if the target name
// can hide the source but these bindings are not obtained.
// avoiding module inconsistency between the resolve process and the finalize process.
// See more details in #124840
return Err((Undetermined, Weak::No));
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/imports/cycle-import-in-std-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@ edition: 2018

// https://github.com/rust-lang/rust/issues/124490

use io::{self as std};
//~^ ERROR: unresolved import `io`
use std::collections::{self as io};

fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/imports/cycle-import-in-std-1.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0432]: unresolved import `io`
--> $DIR/cycle-import-in-std-1.rs:5:10
|
LL | use io::{self as std};
| ^^^^^^^^^^^ no external crate `io`
|
= help: consider importing one of these items instead:
core::io
std::io
std::os::unix::io

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0432`.
9 changes: 9 additions & 0 deletions tests/ui/imports/cycle-import-in-std-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@ edition: 2018

// https://github.com/rust-lang/rust/issues/125013

use io::{self as std};
//~^ ERROR: unresolved import `io`
use std::ops::Deref::{self as io};

fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/imports/cycle-import-in-std-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0432]: unresolved import `io`
--> $DIR/cycle-import-in-std-2.rs:5:10
|
LL | use io::{self as std};
| ^^^^^^^^^^^ no external crate `io`
|
= help: consider importing one of these items instead:
core::io
std::io
std::os::unix::io

error: aborting due to 1 previous error

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

0 comments on commit 713b9fa

Please sign in to comment.