about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2016-10-28 00:30:23 -0700
committerEsteban Küber <esteban@kuber.com.ar>2016-11-09 16:19:49 -0800
commit43aed325aacfbe592fef2acffcf4f888155fb9bf (patch)
tree70af501f414e1fe58a3afe829464bb513c6cf6f1 /src
parentda2ce2276873242a101f205537e7ce297d68f8dd (diff)
downloadrust-43aed325aacfbe592fef2acffcf4f888155fb9bf.tar.gz
rust-43aed325aacfbe592fef2acffcf4f888155fb9bf.zip
Show one error for duplicated type definitions
For the following code:

```rustc
struct Bar;
struct Bar;

fn main () {
}
```

show

```nocode
error[E0428]: a type named `Bar` has already been defined in this module
  --> src/test/compile-fail/E0428.rs:12:1
   |
11 | struct Bar;
   | ----------- previous definition of `Bar` here
12 | struct Bar;
   | ^^^^^^^^^^^

error: aborting due to previous error
```

instead of

```nocode
error[E0428]: a type named `Bar` has already been defined in this module
  --> src/test/compile-fail/E0428.rs:12:1
   |
11 | struct Bar;
   | ----------- previous definition of `Bar` here
12 | struct Bar;
   | ^^^^^^^^^^^

error[E0428]: a value named `Bar` has already been defined in this module
  --> src/test/compile-fail/E0428.rs:12:1
   |
11 | struct Bar;
   | ----------- previous definition of `Bar` here
12 | struct Bar;
   | ^^^^^^^^^^^

error: aborting due to 2 previous errors
```
Diffstat (limited to 'src')
-rw-r--r--src/librustc_resolve/lib.rs14
-rw-r--r--src/test/compile-fail/E0428.rs3
-rw-r--r--src/test/compile-fail/blind-item-block-item-shadow.rs3
-rw-r--r--src/test/compile-fail/double-type-import.rs1
-rw-r--r--src/test/compile-fail/variant-namespacing.rs6
5 files changed, 14 insertions, 13 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index 0c7c1a55a61..fce6d1c5c28 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -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> {
@@ -1270,6 +1273,7 @@ impl<'a> Resolver<'a> {
             builtin_macros: FxHashMap(),
             lexical_macro_resolutions: Vec::new(),
             invocations: invocations,
+            name_already_seen: FxHashMap(),
         }
     }
 
@@ -3396,7 +3400,7 @@ impl<'a> Resolver<'a> {
         }
     }
 
-    fn report_conflict(&self,
+    fn report_conflict(&mut self,
                        parent: Module,
                        name: Name,
                        ns: Namespace,
@@ -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",
@@ -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);
     }
 }
 
diff --git a/src/test/compile-fail/E0428.rs b/src/test/compile-fail/E0428.rs
index 63b4efb73f0..f8502140c44 100644
--- a/src/test/compile-fail/E0428.rs
+++ b/src/test/compile-fail/E0428.rs
@@ -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 () {
 }
diff --git a/src/test/compile-fail/blind-item-block-item-shadow.rs b/src/test/compile-fail/blind-item-block-item-shadow.rs
index 03af0d51ec2..a26b9e3c7aa 100644
--- a/src/test/compile-fail/blind-item-block-item-shadow.rs
+++ b/src/test/compile-fail/blind-item-block-item-shadow.rs
@@ -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
     }
 }
diff --git a/src/test/compile-fail/double-type-import.rs b/src/test/compile-fail/double-type-import.rs
index 923f95e69d1..e51ef5e32e8 100644
--- a/src/test/compile-fail/double-type-import.rs
+++ b/src/test/compile-fail/double-type-import.rs
@@ -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;
diff --git a/src/test/compile-fail/variant-namespacing.rs b/src/test/compile-fail/variant-namespacing.rs
index a8bb94b78fc..3d8e2daaa15 100644
--- a/src/test/compile-fail/variant-namespacing.rs
+++ b/src/test/compile-fail/variant-namespacing.rs
@@ -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() {}