Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit a846cc6

Browse files
Revert "Revert "resolve: Avoid "self-confirming" import resolutions in one more case""
This reverts commit b20bce8. It retains the test added in that commit as a check-pass test, intended to prevent future (unintentional) regressions.
1 parent 5e39baa commit a846cc6

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed

compiler/rustc_resolve/src/imports.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
875875
/// consolidate multiple unresolved import errors into a single diagnostic.
876876
fn finalize_import(&mut self, import: &'b Import<'b>) -> Option<UnresolvedImportError> {
877877
let orig_vis = import.vis.replace(ty::Visibility::Invisible);
878+
let orig_unusable_binding = match &import.kind {
879+
ImportKind::Single { target_bindings, .. } => {
880+
Some(mem::replace(&mut self.r.unusable_binding, target_bindings[TypeNS].get()))
881+
}
882+
_ => None,
883+
};
878884
let prev_ambiguity_errors_len = self.r.ambiguity_errors.len();
879885
let path_res = self.r.resolve_path(
880886
&import.module_path,
@@ -885,6 +891,9 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
885891
import.crate_lint(),
886892
);
887893
let no_ambiguity = self.r.ambiguity_errors.len() == prev_ambiguity_errors_len;
894+
if let Some(orig_unusable_binding) = orig_unusable_binding {
895+
self.r.unusable_binding = orig_unusable_binding;
896+
}
888897
import.vis.set(orig_vis);
889898
if let PathResult::Failed { .. } | PathResult::NonModule(..) = path_res {
890899
// Consider erroneous imports used to avoid duplicate diagnostics.
@@ -895,8 +904,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
895904
// Consistency checks, analogous to `finalize_macro_resolutions`.
896905
if let Some(initial_module) = import.imported_module.get() {
897906
if !ModuleOrUniformRoot::same_def(module, initial_module) && no_ambiguity {
898-
let msg = "inconsistent resolution for an import";
899-
self.r.session.span_err(import.span, msg);
907+
span_bug!(import.span, "inconsistent resolution for an import");
900908
}
901909
} else {
902910
if self.r.privacy_errors.is_empty() {
@@ -918,6 +926,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
918926
}
919927
PathResult::Failed { is_error_from_last_segment: true, span, label, suggestion } => {
920928
if no_ambiguity {
929+
assert!(import.imported_module.get().is_none());
921930
let err = match self.make_path_suggestion(
922931
span,
923932
import.module_path.clone(),

src/test/ui/imports/issue-62767.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// check-pass
2+
13
// Minimized case from #62767.
24
mod m {
35
pub enum Same {
@@ -9,7 +11,7 @@ use m::*;
911

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

1416
// Case from #74556.
1517
mod foo {
@@ -21,8 +23,8 @@ mod foo {
2123
}
2224

2325
use foo::*;
24-
use bar::bar; //~ ERROR unresolved import `bar::bar`
25-
//~| ERROR inconsistent resolution for an import
26+
use bar::bar;
27+
2628
use bar::foobar;
2729

2830
fn main() {}

src/test/ui/imports/issue-62767.stderr

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)