Skip to content

Commit 61181ae

Browse files
committed
Point at def span on redefined name diagnostic
1 parent 3cc68ba commit 61181ae

7 files changed

+25
-30
lines changed

Diff for: src/librustc_resolve/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3840,7 +3840,7 @@ impl<'a> Resolver<'a> {
38403840
false => "defined",
38413841
};
38423842

3843-
let (name, span) = (ident.name, new_binding.span);
3843+
let (name, span) = (ident.name, self.session.codemap().def_span(new_binding.span));
38443844

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

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

38923892
// See https://github.com/rust-lang/rust/issues/32354

Diff for: src/test/ui/blind-item-item-shadow.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0255]: the name `foo` is defined multiple times
22
--> $DIR/blind-item-item-shadow.rs:13:5
33
|
44
11 | mod foo { pub mod foo { } }
5-
| ---------------------------- previous definition of the module `foo` here
5+
| ------- previous definition of the module `foo` here
66
12 |
77
13 | use foo::foo;
88
| ^^^^^^^^ `foo` reimported here

Diff for: src/test/ui/enum-and-module-in-same-scope.stderr

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
error[E0428]: the name `Foo` is defined multiple times
22
--> $DIR/enum-and-module-in-same-scope.rs:15:1
33
|
4-
11 | / enum Foo {
5-
12 | | X
6-
13 | | }
7-
| |_- previous definition of the type `Foo` here
8-
14 |
9-
15 | / mod Foo { //~ ERROR the name `Foo` is defined multiple times
10-
16 | | pub static X: isize = 42;
11-
17 | | fn f() { f() } // Check that this does not result in a resolution error
12-
18 | | }
13-
| |_^ `Foo` redefined here
4+
11 | enum Foo {
5+
| -------- previous definition of the type `Foo` here
6+
...
7+
15 | mod Foo { //~ ERROR the name `Foo` is defined multiple times
8+
| ^^^^^^^ `Foo` redefined here
149
|
1510
= note: `Foo` must be defined only once in the type namespace of this module
1611

Diff for: src/test/ui/issue-19498.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ error[E0255]: the name `A` is defined multiple times
55
| ------- previous import of the module `A` here
66
12 | use self::B;
77
13 | mod A {} //~ ERROR the name `A` is defined multiple times
8-
| ^^^^^^^^ `A` redefined here
8+
| ^^^^^ `A` redefined here
99
|
1010
= note: `A` must be defined only once in the type namespace of this module
1111
help: You can use `as` to change the binding name of the import
@@ -20,7 +20,7 @@ error[E0255]: the name `B` is defined multiple times
2020
| ------- previous import of the module `B` here
2121
...
2222
15 | pub mod B {} //~ ERROR the name `B` is defined multiple times
23-
| ^^^^^^^^^^^^ `B` redefined here
23+
| ^^^^^^^^^ `B` redefined here
2424
|
2525
= note: `B` must be defined only once in the type namespace of this module
2626
help: You can use `as` to change the binding name of the import
@@ -34,7 +34,7 @@ error[E0255]: the name `D` is defined multiple times
3434
18 | use C::D;
3535
| ---- previous import of the module `D` here
3636
19 | mod D {} //~ ERROR the name `D` is defined multiple times
37-
| ^^^^^^^^ `D` redefined here
37+
| ^^^^^ `D` redefined here
3838
|
3939
= note: `D` must be defined only once in the type namespace of this module
4040
help: You can use `as` to change the binding name of the import

Diff for: src/test/ui/issue-21546.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0428]: the name `Foo` is defined multiple times
22
--> $DIR/issue-21546.rs:17:1
33
|
44
14 | mod Foo { }
5-
| ----------- previous definition of the module `Foo` here
5+
| ------- previous definition of the module `Foo` here
66
...
77
17 | struct Foo;
88
| ^^^^^^^^^^^ `Foo` redefined here
@@ -13,7 +13,7 @@ error[E0428]: the name `Bar` is defined multiple times
1313
--> $DIR/issue-21546.rs:24:1
1414
|
1515
21 | mod Bar { }
16-
| ----------- previous definition of the module `Bar` here
16+
| ------- previous definition of the module `Bar` here
1717
...
1818
24 | struct Bar(i32);
1919
| ^^^^^^^^^^^^^^^^ `Bar` redefined here
@@ -27,18 +27,18 @@ error[E0428]: the name `Baz` is defined multiple times
2727
| ---------------- previous definition of the type `Baz` here
2828
...
2929
32 | mod Baz { }
30-
| ^^^^^^^^^^^ `Baz` redefined here
30+
| ^^^^^^^ `Baz` redefined here
3131
|
3232
= note: `Baz` must be defined only once in the type namespace of this module
3333

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

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

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

Diff for: src/test/ui/issue-24081.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ error[E0255]: the name `Sub` is defined multiple times
2020
| ------------- previous import of the trait `Sub` here
2121
...
2222
19 | struct Sub { x: f32 } //~ ERROR the name `Sub` is defined multiple times
23-
| ^^^^^^^^^^^^^^^^^^^^^ `Sub` redefined here
23+
| ^^^^^^^^^^ `Sub` redefined here
2424
|
2525
= note: `Sub` must be defined only once in the type namespace of this module
2626
help: You can use `as` to change the binding name of the import
@@ -35,7 +35,7 @@ error[E0255]: the name `Mul` is defined multiple times
3535
| ------------- previous import of the trait `Mul` here
3636
...
3737
21 | enum Mul { A, B } //~ ERROR the name `Mul` is defined multiple times
38-
| ^^^^^^^^^^^^^^^^^ `Mul` redefined here
38+
| ^^^^^^^^ `Mul` redefined here
3939
|
4040
= note: `Mul` must be defined only once in the type namespace of this module
4141
help: You can use `as` to change the binding name of the import
@@ -50,7 +50,7 @@ error[E0255]: the name `Div` is defined multiple times
5050
| ------------- previous import of the trait `Div` here
5151
...
5252
23 | mod Div { } //~ ERROR the name `Div` is defined multiple times
53-
| ^^^^^^^^^^^ `Div` redefined here
53+
| ^^^^^^^ `Div` redefined here
5454
|
5555
= note: `Div` must be defined only once in the type namespace of this module
5656
help: You can use `as` to change the binding name of the import
@@ -65,7 +65,7 @@ error[E0255]: the name `Rem` is defined multiple times
6565
| ------------- previous import of the trait `Rem` here
6666
...
6767
25 | trait Rem { } //~ ERROR the name `Rem` is defined multiple times
68-
| ^^^^^^^^^^^^^^ `Rem` redefined here
68+
| ^^^^^^^^^ `Rem` redefined here
6969
|
7070
= note: `Rem` must be defined only once in the type namespace of this module
7171
help: You can use `as` to change the binding name of the import

Diff for: src/test/ui/resolve-conflict-item-vs-import.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ error[E0255]: the name `transmute` is defined multiple times
55
| ------------------- previous import of the value `transmute` here
66
12 |
77
13 | fn transmute() {}
8-
| ^^^^^^^^^^^^^^^^^ `transmute` redefined here
8+
| ^^^^^^^^^^^^^^ `transmute` redefined here
99
|
1010
= note: `transmute` must be defined only once in the value namespace of this module
1111
help: You can use `as` to change the binding name of the import

0 commit comments

Comments
 (0)