Skip to content
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

Revert "Revert "resolve: Avoid "self-confirming" import resolutions in one more case"" #78784

Merged
merged 1 commit into from
Nov 8, 2020
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
13 changes: 11 additions & 2 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
/// consolidate multiple unresolved import errors into a single diagnostic.
fn finalize_import(&mut self, import: &'b Import<'b>) -> Option<UnresolvedImportError> {
let orig_vis = import.vis.replace(ty::Visibility::Invisible);
let orig_unusable_binding = match &import.kind {
ImportKind::Single { target_bindings, .. } => {
Some(mem::replace(&mut self.r.unusable_binding, target_bindings[TypeNS].get()))
}
_ => None,
};
let prev_ambiguity_errors_len = self.r.ambiguity_errors.len();
let path_res = self.r.resolve_path(
&import.module_path,
Expand All @@ -882,6 +888,9 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
import.crate_lint(),
);
let no_ambiguity = self.r.ambiguity_errors.len() == prev_ambiguity_errors_len;
if let Some(orig_unusable_binding) = orig_unusable_binding {
self.r.unusable_binding = orig_unusable_binding;
}
import.vis.set(orig_vis);
if let PathResult::Failed { .. } | PathResult::NonModule(..) = path_res {
// Consider erroneous imports used to avoid duplicate diagnostics.
Expand All @@ -892,8 +901,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
// Consistency checks, analogous to `finalize_macro_resolutions`.
if let Some(initial_module) = import.imported_module.get() {
if !ModuleOrUniformRoot::same_def(module, initial_module) && no_ambiguity {
let msg = "inconsistent resolution for an import";
self.r.session.span_err(import.span, msg);
span_bug!(import.span, "inconsistent resolution for an import");
}
} else if self.r.privacy_errors.is_empty() {
let msg = "cannot determine resolution for the import";
Expand All @@ -913,6 +921,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
}
PathResult::Failed { is_error_from_last_segment: true, span, label, suggestion } => {
if no_ambiguity {
assert!(import.imported_module.get().is_none());
let err = match self.make_path_suggestion(
span,
import.module_path.clone(),
Expand Down
8 changes: 5 additions & 3 deletions src/test/ui/imports/issue-62767.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// check-pass

// Minimized case from #62767.
mod m {
pub enum Same {
Expand All @@ -9,7 +11,7 @@ use m::*;

// The variant `Same` introduced by this import is also considered when resolving the prefix
// `Same::` during import validation to avoid effects similar to time travel (#74556).
use Same::Same; //~ ERROR unresolved import `Same`
use Same::Same;

// Case from #74556.
mod foo {
Expand All @@ -21,8 +23,8 @@ mod foo {
}

use foo::*;
use bar::bar; //~ ERROR unresolved import `bar::bar`
//~| ERROR inconsistent resolution for an import
Mark-Simulacrum marked this conversation as resolved.
Show resolved Hide resolved
use bar::bar;

use bar::foobar;

fn main() {}
21 changes: 0 additions & 21 deletions src/test/ui/imports/issue-62767.stderr

This file was deleted.