Skip to content

Show one error for duplicated type definitions #37447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,9 @@ pub struct Resolver<'a> {

// Maps the `Mark` of an expansion to its containing module or block.
invocations: FxHashMap<Mark, &'a InvocationData<'a>>,

// Avoid duplicated errors for "name already defined".
name_already_seen: FxHashMap<Name, Span>,
}

pub struct ResolverArenas<'a> {
Expand Down Expand Up @@ -1270,6 +1273,7 @@ impl<'a> Resolver<'a> {
builtin_macros: FxHashMap(),
lexical_macro_resolutions: Vec::new(),
invocations: invocations,
name_already_seen: FxHashMap(),
}
}

Expand Down Expand Up @@ -3396,7 +3400,7 @@ impl<'a> Resolver<'a> {
}
}

fn report_conflict(&self,
fn report_conflict(&mut self,
parent: Module,
name: Name,
ns: Namespace,
Expand All @@ -3420,6 +3424,13 @@ impl<'a> Resolver<'a> {
};

let span = binding.span;

if let Some(s) = self.name_already_seen.get(&name) {
if s == &span {
return;
}
}

let msg = {
let kind = match (ns, old_binding.module()) {
(ValueNS, _) => "a value",
Expand Down Expand Up @@ -3471,6 +3482,7 @@ impl<'a> Resolver<'a> {
err.span_label(old_binding.span, &format!("previous {} of `{}` here", noun, name));
}
err.emit();
self.name_already_seen.insert(name, span);
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/test/compile-fail/E0428.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
// except according to those terms.

struct Bar; //~ previous definition of `Bar` here
//~| previous definition of `Bar` here
struct Bar; //~ ERROR E0428
//~| NOTE already defined
//~| ERROR E0428
//~| NOTE already defined

fn main () {
}
3 changes: 1 addition & 2 deletions src/test/compile-fail/blind-item-block-item-shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ fn main() {
{
struct Bar;
use foo::Bar;
//~^ ERROR a type named `Bar` has already been defined in this block
//~^^ ERROR a value named `Bar` has already been defined in this block
//~^ ERROR a value named `Bar` has already been defined in this block
}
}
1 change: 0 additions & 1 deletion src/test/compile-fail/double-type-import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ mod foo {
pub use self::bar::X;
use self::bar::X;
//~^ ERROR a value named `X` has already been imported in this module
//~| ERROR a type named `X` has already been imported in this module

mod bar {
pub struct X;
Expand Down
6 changes: 0 additions & 6 deletions src/test/compile-fail/variant-namespacing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,11 @@ const XUnit: u8 = 0;
extern crate variant_namespacing;
pub use variant_namespacing::XE::*;
//~^ ERROR `XStruct` has already been defined
//~| ERROR `XStruct` has already been defined
//~| ERROR `XTuple` has already been defined
//~| ERROR `XTuple` has already been defined
//~| ERROR `XUnit` has already been defined
//~| ERROR `XUnit` has already been defined
pub use E::*;
//~^ ERROR `Struct` has already been defined
//~| ERROR `Struct` has already been defined
//~| ERROR `Tuple` has already been defined
//~| ERROR `Tuple` has already been defined
//~| ERROR `Unit` has already been defined
//~| ERROR `Unit` has already been defined

fn main() {}