Skip to content

Commit 771cc7f

Browse files
committed
Auto merge of #78784 - Mark-Simulacrum:revert-77421, r=petrochenkov
Revert "Revert "resolve: Avoid "self-confirming" import resolutions in one more case"" Specifically, this reverts commit b20bce8 from #77421 to fix #77586. The lang team has decided that for the time being we want to avoid the breakage here (perhaps for a future edition; though almost certainly not the upcoming one), though a future PR may want to add a lint around this case (and perhaps others) which are unlikely to be readable code. r? `@petrochenkov` to confirm this is the right way to fix #77586.
2 parents b2d115f + ae4f80b commit 771cc7f

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed

compiler/rustc_resolve/src/imports.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,12 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
872872
/// consolidate multiple unresolved import errors into a single diagnostic.
873873
fn finalize_import(&mut self, import: &'b Import<'b>) -> Option<UnresolvedImportError> {
874874
let orig_vis = import.vis.replace(ty::Visibility::Invisible);
875+
let orig_unusable_binding = match &import.kind {
876+
ImportKind::Single { target_bindings, .. } => {
877+
Some(mem::replace(&mut self.r.unusable_binding, target_bindings[TypeNS].get()))
878+
}
879+
_ => None,
880+
};
875881
let prev_ambiguity_errors_len = self.r.ambiguity_errors.len();
876882
let path_res = self.r.resolve_path(
877883
&import.module_path,
@@ -882,6 +888,9 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
882888
import.crate_lint(),
883889
);
884890
let no_ambiguity = self.r.ambiguity_errors.len() == prev_ambiguity_errors_len;
891+
if let Some(orig_unusable_binding) = orig_unusable_binding {
892+
self.r.unusable_binding = orig_unusable_binding;
893+
}
885894
import.vis.set(orig_vis);
886895
if let PathResult::Failed { .. } | PathResult::NonModule(..) = path_res {
887896
// Consider erroneous imports used to avoid duplicate diagnostics.
@@ -892,8 +901,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
892901
// Consistency checks, analogous to `finalize_macro_resolutions`.
893902
if let Some(initial_module) = import.imported_module.get() {
894903
if !ModuleOrUniformRoot::same_def(module, initial_module) && no_ambiguity {
895-
let msg = "inconsistent resolution for an import";
896-
self.r.session.span_err(import.span, msg);
904+
span_bug!(import.span, "inconsistent resolution for an import");
897905
}
898906
} else if self.r.privacy_errors.is_empty() {
899907
let msg = "cannot determine resolution for the import";
@@ -913,6 +921,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
913921
}
914922
PathResult::Failed { is_error_from_last_segment: true, span, label, suggestion } => {
915923
if no_ambiguity {
924+
assert!(import.imported_module.get().is_none());
916925
let err = match self.make_path_suggestion(
917926
span,
918927
import.module_path.clone(),

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

+5-3
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

-21
This file was deleted.

0 commit comments

Comments
 (0)