Skip to content

Commit 92f5dea

Browse files
committed
Auto merge of #109602 - bvanjoi:fix-issue-109343, r=petrochenkov
fix(resolve): replace bindings to dummy for unresolved imports close #109343 In #109343, `f` in `pub use f as g` points to: |namespace| binding| |-|-| |type| `external crate f`| |value| `None` | |macro| `None` | When resolve `value_ns` during `resolve_doc_links`, the value of the binding of single_import `pub use f as g` goes to `pub use inner::f`, and since it does not satisfy [!self.is_accessible_from(binding.vis, single_import.parent_scope.module)](https://github.com/rust-lang/rust/blob/master/compiler/rustc_resolve/src/ident.rs#L971) and returns `Err(Undetermined)`, which eventually goes to `PathResult::Indeterminate => unreachable!`. This PR replace all namespace binding to `dummy_binding` for indeterminate import, so, the bindings of `pub use f as g` had been changed to followings after finalize: |namespace| binding| |-|-| |type| `dummy`| |value| `dummy` | |macro| `dummy` | r?`@petrochenkov`
2 parents c9dc55d + f34678c commit 92f5dea

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
405405
t
406406
}
407407

408-
// Define a dummy resolution containing a `Res::Err` as a placeholder for a failed resolution,
409-
// also mark such failed imports as used to avoid duplicate diagnostics.
410-
fn import_dummy_binding(&mut self, import: &'a Import<'a>) {
408+
// Define a dummy resolution containing a `Res::Err` as a placeholder for a failed
409+
// or indeterminate resolution, also mark such failed imports as used to avoid duplicate diagnostics.
410+
fn import_dummy_binding(&mut self, import: &'a Import<'a>, is_indeterminate: bool) {
411411
if let ImportKind::Single { target, ref target_bindings, .. } = import.kind {
412-
if target_bindings.iter().any(|binding| binding.get().is_some()) {
412+
if !(is_indeterminate || target_bindings.iter().all(|binding| binding.get().is_none()))
413+
{
413414
return; // Has resolution, do not create the dummy binding
414415
}
415416
let dummy_binding = self.dummy_binding;
@@ -474,7 +475,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
474475

475476
// If this import is unresolved then create a dummy import
476477
// resolution for it so that later resolve stages won't complain.
477-
self.import_dummy_binding(import);
478+
self.import_dummy_binding(import, is_indeterminate);
478479

479480
if let Some(err) = unresolved_import_error {
480481
if let ImportKind::Single { source, ref source_bindings, .. } = import.kind {

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

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub mod rustdoc;
8585

8686
fluent_messages! { "../messages.ftl" }
8787

88+
#[derive(Debug)]
8889
enum Weak {
8990
Yes,
9091
No,

Diff for: compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ pub enum TrimmedDefPaths {
421421
GoodPath,
422422
}
423423

424-
#[derive(Clone, Hash)]
424+
#[derive(Clone, Hash, Debug)]
425425
pub enum ResolveDocLinks {
426426
/// Do not resolve doc links.
427427
None,

Diff for: tests/ui/imports/issue-109343.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![crate_type = "lib"]
2+
3+
pub mod f {}
4+
pub use unresolved::f;
5+
//~^ ERROR unresolved import `unresolved`
6+
7+
/// [g]
8+
pub use f as g;
9+
10+
fn main() {}

Diff for: tests/ui/imports/issue-109343.stderr

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0432]: unresolved import `unresolved`
2+
--> $DIR/issue-109343.rs:4:9
3+
|
4+
LL | pub use unresolved::f;
5+
| ^^^^^^^^^^ maybe a missing crate `unresolved`?
6+
|
7+
= help: consider adding `extern crate unresolved` to use the `unresolved` crate
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0432`.

0 commit comments

Comments
 (0)