mark undetermined if target binding in current ns is not got
This commit is contained in:
parent
6b65c30f8e
commit
2f17535584
@ -966,7 +966,7 @@ fn resolve_ident_in_module_unadjusted_ext(
|
|||||||
for single_import in &resolution.single_imports {
|
for single_import in &resolution.single_imports {
|
||||||
let Some(import_vis) = single_import.vis.get() else {
|
let Some(import_vis) = single_import.vis.get() else {
|
||||||
// This branch handles a cycle in single imports, which occurs
|
// This branch handles a cycle in single imports, which occurs
|
||||||
// when we've previously captured the `vis` value during an import
|
// when we've previously **steal** the `vis` value during an import
|
||||||
// process.
|
// process.
|
||||||
//
|
//
|
||||||
// For example:
|
// For example:
|
||||||
@ -998,21 +998,28 @@ fn resolve_ident_in_module_unadjusted_ext(
|
|||||||
let Some(module) = single_import.imported_module.get() else {
|
let Some(module) = single_import.imported_module.get() else {
|
||||||
return Err((Undetermined, Weak::No));
|
return Err((Undetermined, Weak::No));
|
||||||
};
|
};
|
||||||
let ImportKind::Single { source: ident, target, target_bindings, .. } =
|
let ImportKind::Single { source, target, target_bindings, .. } = &single_import.kind
|
||||||
&single_import.kind
|
|
||||||
else {
|
else {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
};
|
};
|
||||||
if (ident != target) && target_bindings.iter().all(|binding| binding.get().is_none()) {
|
if source != target {
|
||||||
// This branch allows the binding to be defined or updated later if the target name
|
// 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.
|
// can hide the source.
|
||||||
// avoiding module inconsistency between the resolve process and the finalize process.
|
if target_bindings.iter().all(|binding| binding.get().is_none()) {
|
||||||
|
// None of the target bindings are available, so we can't determine
|
||||||
|
// if this binding is correct or not.
|
||||||
// See more details in #124840
|
// See more details in #124840
|
||||||
return Err((Undetermined, Weak::No));
|
return Err((Undetermined, Weak::No));
|
||||||
|
} else if target_bindings[ns].get().is_none() && binding.is_some() {
|
||||||
|
// `binding.is_some()` avoids the condition where the binding
|
||||||
|
// truly doesn't exist in this namespace and should return `Err(Determined)`.
|
||||||
|
return Err((Undetermined, Weak::No));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match self.resolve_ident_in_module(
|
match self.resolve_ident_in_module(
|
||||||
module,
|
module,
|
||||||
*ident,
|
*source,
|
||||||
ns,
|
ns,
|
||||||
&single_import.parent_scope,
|
&single_import.parent_scope,
|
||||||
None,
|
None,
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
//@ known-bug: rust-lang/rust#126376
|
|
||||||
mod a {
|
|
||||||
pub mod b {
|
|
||||||
pub mod c {
|
|
||||||
pub trait D {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
use a::*;
|
|
||||||
use e as b;
|
|
||||||
use b::c::D as e;
|
|
||||||
|
|
||||||
fn e() {}
|
|
@ -1,15 +0,0 @@
|
|||||||
//@ known-bug: rust-lang/rust#126389
|
|
||||||
|
|
||||||
mod a {
|
|
||||||
pub mod b {
|
|
||||||
pub mod c {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
use a::*;
|
|
||||||
|
|
||||||
use b::c;
|
|
||||||
|
|
||||||
use c as b;
|
|
||||||
|
|
||||||
fn c() {}
|
|
19
tests/ui/imports/shadow-glob-module-resolution-3.rs
Normal file
19
tests/ui/imports/shadow-glob-module-resolution-3.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// https://github.com/rust-lang/rust/issues/126389
|
||||||
|
|
||||||
|
mod a {
|
||||||
|
pub mod b {
|
||||||
|
pub mod c {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
use a::*;
|
||||||
|
|
||||||
|
use b::c;
|
||||||
|
//~^ ERROR: unresolved import `b::c`
|
||||||
|
//~| ERROR: cannot determine resolution for the import
|
||||||
|
//~| ERROR: cannot determine resolution for the import
|
||||||
|
use c as b;
|
||||||
|
|
||||||
|
fn c() {}
|
||||||
|
|
||||||
|
fn main() { }
|
23
tests/ui/imports/shadow-glob-module-resolution-3.stderr
Normal file
23
tests/ui/imports/shadow-glob-module-resolution-3.stderr
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
error: cannot determine resolution for the import
|
||||||
|
--> $DIR/shadow-glob-module-resolution-3.rs:11:5
|
||||||
|
|
|
||||||
|
LL | use b::c;
|
||||||
|
| ^^^^
|
||||||
|
|
||||||
|
error: cannot determine resolution for the import
|
||||||
|
--> $DIR/shadow-glob-module-resolution-3.rs:11:5
|
||||||
|
|
|
||||||
|
LL | use b::c;
|
||||||
|
| ^^^^
|
||||||
|
|
|
||||||
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||||
|
|
||||||
|
error[E0432]: unresolved import `b::c`
|
||||||
|
--> $DIR/shadow-glob-module-resolution-3.rs:11:5
|
||||||
|
|
|
||||||
|
LL | use b::c;
|
||||||
|
| ^^^^
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0432`.
|
20
tests/ui/imports/shadow-glob-module-resolution-4.rs
Normal file
20
tests/ui/imports/shadow-glob-module-resolution-4.rs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// https://github.com/rust-lang/rust/issues/126376
|
||||||
|
|
||||||
|
mod a {
|
||||||
|
pub mod b {
|
||||||
|
pub trait C {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
use a::*;
|
||||||
|
|
||||||
|
use e as b;
|
||||||
|
|
||||||
|
use b::C as e;
|
||||||
|
//~^ ERROR: unresolved import `b::C`
|
||||||
|
//~| ERROR: cannot determine resolution for the import
|
||||||
|
//~| ERROR: cannot determine resolution for the import
|
||||||
|
|
||||||
|
fn e() {}
|
||||||
|
|
||||||
|
fn main() { }
|
23
tests/ui/imports/shadow-glob-module-resolution-4.stderr
Normal file
23
tests/ui/imports/shadow-glob-module-resolution-4.stderr
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
error: cannot determine resolution for the import
|
||||||
|
--> $DIR/shadow-glob-module-resolution-4.rs:13:5
|
||||||
|
|
|
||||||
|
LL | use b::C as e;
|
||||||
|
| ^^^^^^^^^
|
||||||
|
|
||||||
|
error: cannot determine resolution for the import
|
||||||
|
--> $DIR/shadow-glob-module-resolution-4.rs:13:5
|
||||||
|
|
|
||||||
|
LL | use b::C as e;
|
||||||
|
| ^^^^^^^^^
|
||||||
|
|
|
||||||
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||||
|
|
||||||
|
error[E0432]: unresolved import `b::C`
|
||||||
|
--> $DIR/shadow-glob-module-resolution-4.rs:13:5
|
||||||
|
|
|
||||||
|
LL | use b::C as e;
|
||||||
|
| ^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0432`.
|
Loading…
Reference in New Issue
Block a user