Skip to content

Commit af8f722

Browse files
authored
Rollup merge of #105208 - chenyukang:yukang/fix-105069, r=cjgillot
Add AmbiguityError for inconsistent resolution for an import Fixes #105069 Fixes #83950
2 parents f91fa51 + 795b2af commit af8f722

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

compiler/rustc_resolve/src/imports.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use crate::diagnostics::{import_candidates, Suggestion};
44
use crate::Determinacy::{self, *};
55
use crate::Namespace::*;
66
use crate::{module_to_string, names_to_string, ImportSuggestion};
7-
use crate::{AmbiguityKind, BindingKey, ModuleKind, ResolutionError, Resolver, Segment};
7+
use crate::{
8+
AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, BindingKey, ModuleKind, ResolutionError,
9+
Resolver, Segment,
10+
};
811
use crate::{Finalize, Module, ModuleOrUniformRoot, ParentScope, PerNS, ScopeSet};
912
use crate::{NameBinding, NameBindingKind, PathResult};
1013

@@ -791,7 +794,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
791794
match binding {
792795
Ok(binding) => {
793796
// Consistency checks, analogous to `finalize_macro_resolutions`.
794-
let initial_res = source_bindings[ns].get().map(|initial_binding| {
797+
let initial_binding = source_bindings[ns].get().map(|initial_binding| {
795798
all_ns_err = false;
796799
if let Some(target_binding) = target_bindings[ns].get() {
797800
if target.name == kw::Underscore
@@ -805,12 +808,20 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
805808
);
806809
}
807810
}
808-
initial_binding.res()
811+
initial_binding
809812
});
810813
let res = binding.res();
811-
if let Ok(initial_res) = initial_res {
814+
if let Ok(initial_binding) = initial_binding {
815+
let initial_res = initial_binding.res();
812816
if res != initial_res && this.ambiguity_errors.is_empty() {
813-
span_bug!(import.span, "inconsistent resolution for an import");
817+
this.ambiguity_errors.push(AmbiguityError {
818+
kind: AmbiguityKind::Import,
819+
ident,
820+
b1: initial_binding,
821+
b2: binding,
822+
misc1: AmbiguityErrorMisc::None,
823+
misc2: AmbiguityErrorMisc::None,
824+
});
814825
}
815826
} else if res != Res::Err
816827
&& this.ambiguity_errors.is_empty()

src/test/ui/resolve/issue-105069.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use self::A::*;
2+
use V; //~ ERROR `V` is ambiguous
3+
use self::B::*;
4+
enum A {
5+
V
6+
}
7+
enum B {
8+
V
9+
}
10+
11+
fn main() {}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0659]: `V` is ambiguous
2+
--> $DIR/issue-105069.rs:2:5
3+
|
4+
LL | use V;
5+
| ^ ambiguous name
6+
|
7+
= note: ambiguous because of multiple potential import sources
8+
note: `V` could refer to the variant imported here
9+
--> $DIR/issue-105069.rs:1:5
10+
|
11+
LL | use self::A::*;
12+
| ^^^^^^^^^^
13+
note: `V` could also refer to the variant imported here
14+
--> $DIR/issue-105069.rs:3:5
15+
|
16+
LL | use self::B::*;
17+
| ^^^^^^^^^^
18+
19+
error: aborting due to previous error
20+
21+
For more information about this error, try `rustc --explain E0659`.

0 commit comments

Comments
 (0)