Skip to content

fix(resolve): replace bindings to dummy for unresolved imports #109602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
t
}

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

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

if let Some(err) = unresolved_import_error {
if let ImportKind::Single { source, ref source_bindings, .. } = import.kind {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub mod rustdoc;

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

#[derive(Debug)]
enum Weak {
Yes,
No,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ pub enum TrimmedDefPaths {
GoodPath,
}

#[derive(Clone, Hash)]
#[derive(Clone, Hash, Debug)]
pub enum ResolveDocLinks {
/// Do not resolve doc links.
None,
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/imports/issue-109343.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![crate_type = "lib"]

pub mod f {}
pub use unresolved::f;
//~^ ERROR unresolved import `unresolved`

/// [g]
pub use f as g;

fn main() {}
11 changes: 11 additions & 0 deletions tests/ui/imports/issue-109343.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0432]: unresolved import `unresolved`
--> $DIR/issue-109343.rs:4:9
|
LL | pub use unresolved::f;
| ^^^^^^^^^^ maybe a missing crate `unresolved`?
|
= help: consider adding `extern crate unresolved` to use the `unresolved` crate

error: aborting due to previous error

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