Skip to content

Commit b20bce8

Browse files
committed
Revert "resolve: Avoid "self-confirming" import resolutions in one more case"
1 parent 8fe73e8 commit b20bce8

File tree

3 files changed

+41
-16
lines changed

3 files changed

+41
-16
lines changed

compiler/rustc_resolve/src/imports.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -875,12 +875,6 @@ 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-
};
884878
let prev_ambiguity_errors_len = self.r.ambiguity_errors.len();
885879
let path_res = self.r.resolve_path(
886880
&import.module_path,
@@ -891,9 +885,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
891885
import.crate_lint(),
892886
);
893887
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-
}
897888
import.vis.set(orig_vis);
898889
if let PathResult::Failed { .. } | PathResult::NonModule(..) = path_res {
899890
// Consider erroneous imports used to avoid duplicate diagnostics.
@@ -904,7 +895,8 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
904895
// Consistency checks, analogous to `finalize_macro_resolutions`.
905896
if let Some(initial_module) = import.imported_module.get() {
906897
if !ModuleOrUniformRoot::same_def(module, initial_module) && no_ambiguity {
907-
span_bug!(import.span, "inconsistent resolution for an import");
898+
let msg = "inconsistent resolution for an import";
899+
self.r.session.span_err(import.span, msg);
908900
}
909901
} else {
910902
if self.r.privacy_errors.is_empty() {
@@ -926,7 +918,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
926918
}
927919
PathResult::Failed { is_error_from_last_segment: true, span, label, suggestion } => {
928920
if no_ambiguity {
929-
assert!(import.imported_module.get().is_none());
930921
let err = match self.make_path_suggestion(
931922
span,
932923
import.module_path.clone(),

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

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// check-pass
2-
1+
// Minimized case from #62767.
32
mod m {
43
pub enum Same {
54
Same,
@@ -8,8 +7,22 @@ mod m {
87

98
use m::*;
109

11-
// The variant `Same` introduced by this import is not considered when resolving the prefix
12-
// `Same::` during import validation (issue #62767).
13-
use Same::Same;
10+
// The variant `Same` introduced by this import is also considered when resolving the prefix
11+
// `Same::` during import validation to avoid effects similar to time travel (#74556).
12+
use Same::Same; //~ ERROR unresolved import `Same`
13+
14+
// Case from #74556.
15+
mod foo {
16+
pub mod bar {
17+
pub mod bar {
18+
pub fn foobar() {}
19+
}
20+
}
21+
}
22+
23+
use foo::*;
24+
use bar::bar; //~ ERROR unresolved import `bar::bar`
25+
//~| ERROR inconsistent resolution for an import
26+
use bar::foobar;
1427

1528
fn main() {}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error: inconsistent resolution for an import
2+
--> $DIR/issue-62767.rs:24:5
3+
|
4+
LL | use bar::bar;
5+
| ^^^^^^^^
6+
7+
error[E0432]: unresolved import `Same`
8+
--> $DIR/issue-62767.rs:12:5
9+
|
10+
LL | use Same::Same;
11+
| ^^^^ `Same` is a variant, not a module
12+
13+
error[E0432]: unresolved import `bar::bar`
14+
--> $DIR/issue-62767.rs:24:5
15+
|
16+
LL | use bar::bar;
17+
| ^^^^^^^^ no `bar` in `foo::bar::bar`
18+
19+
error: aborting due to 3 previous errors
20+
21+
For more information about this error, try `rustc --explain E0432`.

0 commit comments

Comments
 (0)