Skip to content

Commit

Permalink
fix #105069, Add AmbiguityError for inconsistent resolution for an im…
Browse files Browse the repository at this point in the history
…port
  • Loading branch information
chenyukang committed Dec 3, 2022
1 parent 703d95e commit 795b2af
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
21 changes: 16 additions & 5 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use crate::diagnostics::{import_candidates, Suggestion};
use crate::Determinacy::{self, *};
use crate::Namespace::*;
use crate::{module_to_string, names_to_string, ImportSuggestion};
use crate::{AmbiguityKind, BindingKey, ModuleKind, ResolutionError, Resolver, Segment};
use crate::{
AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, BindingKey, ModuleKind, ResolutionError,
Resolver, Segment,
};
use crate::{Finalize, Module, ModuleOrUniformRoot, ParentScope, PerNS, ScopeSet};
use crate::{NameBinding, NameBindingKind, PathResult};

Expand Down Expand Up @@ -791,7 +794,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
match binding {
Ok(binding) => {
// Consistency checks, analogous to `finalize_macro_resolutions`.
let initial_res = source_bindings[ns].get().map(|initial_binding| {
let initial_binding = source_bindings[ns].get().map(|initial_binding| {
all_ns_err = false;
if let Some(target_binding) = target_bindings[ns].get() {
if target.name == kw::Underscore
Expand All @@ -805,12 +808,20 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
);
}
}
initial_binding.res()
initial_binding
});
let res = binding.res();
if let Ok(initial_res) = initial_res {
if let Ok(initial_binding) = initial_binding {
let initial_res = initial_binding.res();
if res != initial_res && this.ambiguity_errors.is_empty() {
span_bug!(import.span, "inconsistent resolution for an import");
this.ambiguity_errors.push(AmbiguityError {
kind: AmbiguityKind::Import,
ident,
b1: initial_binding,
b2: binding,
misc1: AmbiguityErrorMisc::None,
misc2: AmbiguityErrorMisc::None,
});
}
} else if res != Res::Err
&& this.ambiguity_errors.is_empty()
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/resolve/issue-105069.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use self::A::*;
use V; //~ ERROR `V` is ambiguous
use self::B::*;
enum A {
V
}
enum B {
V
}

fn main() {}
21 changes: 21 additions & 0 deletions src/test/ui/resolve/issue-105069.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error[E0659]: `V` is ambiguous
--> $DIR/issue-105069.rs:2:5
|
LL | use V;
| ^ ambiguous name
|
= note: ambiguous because of multiple potential import sources
note: `V` could refer to the variant imported here
--> $DIR/issue-105069.rs:1:5
|
LL | use self::A::*;
| ^^^^^^^^^^
note: `V` could also refer to the variant imported here
--> $DIR/issue-105069.rs:3:5
|
LL | use self::B::*;
| ^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0659`.

0 comments on commit 795b2af

Please sign in to comment.