Skip to content

Commit

Permalink
Rollup merge of rust-lang#46802 - estebank:redefined-def-span, r=mich…
Browse files Browse the repository at this point in the history
…aelwoerister

Point at def span on redefined name diagnostic
  • Loading branch information
GuillaumeGomez authored Dec 18, 2017
2 parents 12cd452 + 61181ae commit 015502c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 30 deletions.
6 changes: 3 additions & 3 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3840,7 +3840,7 @@ impl<'a> Resolver<'a> {
false => "defined",
};

let (name, span) = (ident.name, new_binding.span);
let (name, span) = (ident.name, self.session.codemap().def_span(new_binding.span));

if let Some(s) = self.name_already_seen.get(&name) {
if s == &span {
Expand Down Expand Up @@ -3885,8 +3885,8 @@ impl<'a> Resolver<'a> {

err.span_label(span, format!("`{}` re{} here", name, new_participle));
if old_binding.span != syntax_pos::DUMMY_SP {
err.span_label(old_binding.span, format!("previous {} of the {} `{}` here",
old_noun, old_kind, name));
err.span_label(self.session.codemap().def_span(old_binding.span),
format!("previous {} of the {} `{}` here", old_noun, old_kind, name));
}

// See https://github.com/rust-lang/rust/issues/32354
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/blind-item-item-shadow.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0255]: the name `foo` is defined multiple times
--> $DIR/blind-item-item-shadow.rs:13:5
|
11 | mod foo { pub mod foo { } }
| ---------------------------- previous definition of the module `foo` here
| ------- previous definition of the module `foo` here
12 |
13 | use foo::foo;
| ^^^^^^^^ `foo` reimported here
Expand Down
15 changes: 5 additions & 10 deletions src/test/ui/enum-and-module-in-same-scope.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
error[E0428]: the name `Foo` is defined multiple times
--> $DIR/enum-and-module-in-same-scope.rs:15:1
|
11 | / enum Foo {
12 | | X
13 | | }
| |_- previous definition of the type `Foo` here
14 |
15 | / mod Foo { //~ ERROR the name `Foo` is defined multiple times
16 | | pub static X: isize = 42;
17 | | fn f() { f() } // Check that this does not result in a resolution error
18 | | }
| |_^ `Foo` redefined here
11 | enum Foo {
| -------- previous definition of the type `Foo` here
...
15 | mod Foo { //~ ERROR the name `Foo` is defined multiple times
| ^^^^^^^ `Foo` redefined here
|
= note: `Foo` must be defined only once in the type namespace of this module

Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/issue-19498.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ error[E0255]: the name `A` is defined multiple times
| ------- previous import of the module `A` here
12 | use self::B;
13 | mod A {} //~ ERROR the name `A` is defined multiple times
| ^^^^^^^^ `A` redefined here
| ^^^^^ `A` redefined here
|
= note: `A` must be defined only once in the type namespace of this module
help: You can use `as` to change the binding name of the import
Expand All @@ -20,7 +20,7 @@ error[E0255]: the name `B` is defined multiple times
| ------- previous import of the module `B` here
...
15 | pub mod B {} //~ ERROR the name `B` is defined multiple times
| ^^^^^^^^^^^^ `B` redefined here
| ^^^^^^^^^ `B` redefined here
|
= note: `B` must be defined only once in the type namespace of this module
help: You can use `as` to change the binding name of the import
Expand All @@ -34,7 +34,7 @@ error[E0255]: the name `D` is defined multiple times
18 | use C::D;
| ---- previous import of the module `D` here
19 | mod D {} //~ ERROR the name `D` is defined multiple times
| ^^^^^^^^ `D` redefined here
| ^^^^^ `D` redefined here
|
= note: `D` must be defined only once in the type namespace of this module
help: You can use `as` to change the binding name of the import
Expand Down
16 changes: 8 additions & 8 deletions src/test/ui/issue-21546.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0428]: the name `Foo` is defined multiple times
--> $DIR/issue-21546.rs:17:1
|
14 | mod Foo { }
| ----------- previous definition of the module `Foo` here
| ------- previous definition of the module `Foo` here
...
17 | struct Foo;
| ^^^^^^^^^^^ `Foo` redefined here
Expand All @@ -13,7 +13,7 @@ error[E0428]: the name `Bar` is defined multiple times
--> $DIR/issue-21546.rs:24:1
|
21 | mod Bar { }
| ----------- previous definition of the module `Bar` here
| ------- previous definition of the module `Bar` here
...
24 | struct Bar(i32);
| ^^^^^^^^^^^^^^^^ `Bar` redefined here
Expand All @@ -27,18 +27,18 @@ error[E0428]: the name `Baz` is defined multiple times
| ---------------- previous definition of the type `Baz` here
...
32 | mod Baz { }
| ^^^^^^^^^^^ `Baz` redefined here
| ^^^^^^^ `Baz` redefined here
|
= note: `Baz` must be defined only once in the type namespace of this module

error[E0428]: the name `Qux` is defined multiple times
--> $DIR/issue-21546.rs:40:1
|
37 | struct Qux { x: bool }
| ---------------------- previous definition of the type `Qux` here
| ---------- previous definition of the type `Qux` here
...
40 | mod Qux { }
| ^^^^^^^^^^^ `Qux` redefined here
| ^^^^^^^ `Qux` redefined here
|
= note: `Qux` must be defined only once in the type namespace of this module

Expand All @@ -49,18 +49,18 @@ error[E0428]: the name `Quux` is defined multiple times
| ------------ previous definition of the type `Quux` here
...
48 | mod Quux { }
| ^^^^^^^^^^^^ `Quux` redefined here
| ^^^^^^^^ `Quux` redefined here
|
= note: `Quux` must be defined only once in the type namespace of this module

error[E0428]: the name `Corge` is defined multiple times
--> $DIR/issue-21546.rs:56:1
|
53 | enum Corge { A, B }
| ------------------- previous definition of the type `Corge` here
| ---------- previous definition of the type `Corge` here
...
56 | mod Corge { }
| ^^^^^^^^^^^^^ `Corge` redefined here
| ^^^^^^^^^ `Corge` redefined here
|
= note: `Corge` must be defined only once in the type namespace of this module

Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/issue-24081.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ error[E0255]: the name `Sub` is defined multiple times
| ------------- previous import of the trait `Sub` here
...
19 | struct Sub { x: f32 } //~ ERROR the name `Sub` is defined multiple times
| ^^^^^^^^^^^^^^^^^^^^^ `Sub` redefined here
| ^^^^^^^^^^ `Sub` redefined here
|
= note: `Sub` must be defined only once in the type namespace of this module
help: You can use `as` to change the binding name of the import
Expand All @@ -35,7 +35,7 @@ error[E0255]: the name `Mul` is defined multiple times
| ------------- previous import of the trait `Mul` here
...
21 | enum Mul { A, B } //~ ERROR the name `Mul` is defined multiple times
| ^^^^^^^^^^^^^^^^^ `Mul` redefined here
| ^^^^^^^^ `Mul` redefined here
|
= note: `Mul` must be defined only once in the type namespace of this module
help: You can use `as` to change the binding name of the import
Expand All @@ -50,7 +50,7 @@ error[E0255]: the name `Div` is defined multiple times
| ------------- previous import of the trait `Div` here
...
23 | mod Div { } //~ ERROR the name `Div` is defined multiple times
| ^^^^^^^^^^^ `Div` redefined here
| ^^^^^^^ `Div` redefined here
|
= note: `Div` must be defined only once in the type namespace of this module
help: You can use `as` to change the binding name of the import
Expand All @@ -65,7 +65,7 @@ error[E0255]: the name `Rem` is defined multiple times
| ------------- previous import of the trait `Rem` here
...
25 | trait Rem { } //~ ERROR the name `Rem` is defined multiple times
| ^^^^^^^^^^^^^^ `Rem` redefined here
| ^^^^^^^^^ `Rem` redefined here
|
= note: `Rem` must be defined only once in the type namespace of this module
help: You can use `as` to change the binding name of the import
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/resolve-conflict-item-vs-import.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ error[E0255]: the name `transmute` is defined multiple times
| ------------------- previous import of the value `transmute` here
12 |
13 | fn transmute() {}
| ^^^^^^^^^^^^^^^^^ `transmute` redefined here
| ^^^^^^^^^^^^^^ `transmute` redefined here
|
= note: `transmute` must be defined only once in the value namespace of this module
help: You can use `as` to change the binding name of the import
Expand Down

0 comments on commit 015502c

Please sign in to comment.