Skip to content

Commit 8eb7ac5

Browse files
committed
Use def_span to minimize definition span to first line when possible
1 parent 39c96a0 commit 8eb7ac5

10 files changed

+45
-77
lines changed

src/librustc_resolve/diagnostics.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,10 @@ impl<'a> Resolver<'a> {
782782
);
783783
let def_span = suggestion.res.opt_def_id().and_then(|def_id| match def_id.krate {
784784
LOCAL_CRATE => self.definitions.opt_span(def_id),
785-
_ => Some(self.cstore().get_span_untracked(def_id, self.session)),
785+
_ => Some(self.session.source_map().def_span(self.cstore().get_span_untracked(
786+
def_id,
787+
self.session,
788+
))),
786789
});
787790
if let Some(span) = def_span {
788791
err.span_label(

src/test/ui/derives/deriving-meta-unknown-trait.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | #[derive(Eqr)]
77
::: $SRC_DIR/libcore/cmp.rs:LL:COL
88
|
99
LL | pub macro Eq($item:item) { /* compiler built-in */ }
10-
| ---------------------------------------------------- similarly named derive macro `Eq` defined here
10+
| ------------------------ similarly named derive macro `Eq` defined here
1111

1212
error: cannot find derive macro `Eqr` in this scope
1313
--> $DIR/deriving-meta-unknown-trait.rs:1:10

src/test/ui/issues/issue-17546.stderr

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
error[E0573]: expected type, found variant `NoResult`
22
--> $DIR/issue-17546.rs:12:17
33
|
4-
LL | fn new() -> NoResult<MyEnum, String> {
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^
4+
LL | fn new() -> NoResult<MyEnum, String> {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
::: $SRC_DIR/libcore/result.rs:LL:COL
88
|
9-
LL | / pub enum Result<T, E> {
10-
LL | | /// Contains the success value
11-
LL | | #[stable(feature = "rust1", since = "1.0.0")]
12-
LL | | Ok(#[stable(feature = "rust1", since = "1.0.0")] T),
13-
... |
14-
LL | | Err(#[stable(feature = "rust1", since = "1.0.0")] E),
15-
LL | | }
16-
| |_- similarly named enum `Result` defined here
9+
LL | pub enum Result<T, E> {
10+
| --------------------- similarly named enum `Result` defined here
1711
|
1812
help: try using the variant's enum
1913
|
@@ -63,19 +57,13 @@ LL | use std::result::Result;
6357
error[E0573]: expected type, found variant `NoResult`
6458
--> $DIR/issue-17546.rs:33:15
6559
|
66-
LL | fn newer() -> NoResult<foo::MyEnum, String> {
67-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60+
LL | fn newer() -> NoResult<foo::MyEnum, String> {
61+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6862
|
6963
::: $SRC_DIR/libcore/result.rs:LL:COL
7064
|
71-
LL | / pub enum Result<T, E> {
72-
LL | | /// Contains the success value
73-
LL | | #[stable(feature = "rust1", since = "1.0.0")]
74-
LL | | Ok(#[stable(feature = "rust1", since = "1.0.0")] T),
75-
... |
76-
LL | | Err(#[stable(feature = "rust1", since = "1.0.0")] E),
77-
LL | | }
78-
| |_- similarly named enum `Result` defined here
65+
LL | pub enum Result<T, E> {
66+
| --------------------- similarly named enum `Result` defined here
7967
|
8068
help: try using the variant's enum
8169
|

src/test/ui/issues/issue-7607-1.stderr

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
error[E0412]: cannot find type `Fo` in this scope
22
--> $DIR/issue-7607-1.rs:5:6
33
|
4-
LL | impl Fo {
5-
| ^^ help: a trait with a similar name exists: `Fn`
4+
LL | impl Fo {
5+
| ^^ help: a trait with a similar name exists: `Fn`
66
|
77
::: $SRC_DIR/libcore/ops/function.rs:LL:COL
88
|
9-
LL | / pub trait Fn<Args> : FnMut<Args> {
10-
LL | | /// Performs the call operation.
11-
LL | | #[unstable(feature = "fn_traits", issue = "29625")]
12-
LL | | extern "rust-call" fn call(&self, args: Args) -> Self::Output;
13-
LL | | }
14-
| |_- similarly named trait `Fn` defined here
9+
LL | pub trait Fn<Args> : FnMut<Args> {
10+
| -------------------------------- similarly named trait `Fn` defined here
1511

1612
error: aborting due to previous error
1713

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
error: cannot find macro `printlx` in this scope
22
--> $DIR/macro-name-typo.rs:2:5
33
|
4-
LL | printlx!("oh noes!");
5-
| ^^^^^^^ help: a macro with a similar name exists: `println`
4+
LL | printlx!("oh noes!");
5+
| ^^^^^^^ help: a macro with a similar name exists: `println`
66
|
77
::: $SRC_DIR/libstd/macros.rs:LL:COL
88
|
9-
LL | / macro_rules! println {
10-
LL | | () => ($crate::print!("\n"));
11-
LL | | ($($arg:tt)*) => ({
12-
LL | | $crate::io::_print($crate::format_args_nl!($($arg)*));
13-
LL | | })
14-
LL | | }
15-
| |_- similarly named macro `println` defined here
9+
LL | macro_rules! println {
10+
| -------------------- similarly named macro `println` defined here
1611

1712
error: aborting due to previous error
1813

src/test/ui/macros/macro-path-prelude-fail-3.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | inline!();
77
::: $SRC_DIR/libcore/macros.rs:LL:COL
88
|
99
LL | macro_rules! line { () => { /* compiler built-in */ } }
10-
| ------------------------------------------------------- similarly named macro `line` defined here
10+
| ----------------- similarly named macro `line` defined here
1111

1212
error: aborting due to previous error
1313

src/test/ui/macros/macro-use-wrong-name.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | macro_two!();
77
::: $DIR/auxiliary/two_macros.rs:2:1
88
|
99
LL | macro_rules! macro_one { () => ("one") }
10-
| ---------------------------------------- similarly named macro `macro_one` defined here
10+
| ---------------------- similarly named macro `macro_one` defined here
1111

1212
error: aborting due to previous error
1313

src/test/ui/proc-macro/resolve-error.stderr

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
error: cannot find macro `bang_proc_macrp` in this scope
22
--> $DIR/resolve-error.rs:60:5
33
|
4-
LL | bang_proc_macrp!();
5-
| ^^^^^^^^^^^^^^^ help: a macro with a similar name exists: `bang_proc_macro`
4+
LL | bang_proc_macrp!();
5+
| ^^^^^^^^^^^^^^^ help: a macro with a similar name exists: `bang_proc_macro`
66
|
77
::: $DIR/auxiliary/test-macros.rs:15:1
88
|
9-
LL | / pub fn empty(_: TokenStream) -> TokenStream {
10-
LL | | TokenStream::new()
11-
LL | | }
12-
| |_- similarly named macro `bang_proc_macro` defined here
9+
LL | pub fn empty(_: TokenStream) -> TokenStream {
10+
| ------------------------------------------- similarly named macro `bang_proc_macro` defined here
1311

1412
error: cannot find macro `Dlona` in this scope
1513
--> $DIR/resolve-error.rs:57:5
@@ -60,15 +58,13 @@ LL | #[derive(Dlona)]
6058
error: cannot find derive macro `Dlona` in this scope
6159
--> $DIR/resolve-error.rs:40:10
6260
|
63-
LL | #[derive(Dlona)]
64-
| ^^^^^ help: a derive macro with a similar name exists: `Clona`
61+
LL | #[derive(Dlona)]
62+
| ^^^^^ help: a derive macro with a similar name exists: `Clona`
6563
|
6664
::: $DIR/auxiliary/derive-clona.rs:11:1
6765
|
68-
LL | / pub fn derive_clonea(input: TokenStream) -> TokenStream {
69-
LL | | "".parse().unwrap()
70-
LL | | }
71-
| |_- similarly named derive macro `Clona` defined here
66+
LL | pub fn derive_clonea(input: TokenStream) -> TokenStream {
67+
| ------------------------------------------------------- similarly named derive macro `Clona` defined here
7268

7369
error: cannot find derive macro `Dlone` in this scope
7470
--> $DIR/resolve-error.rs:35:10
@@ -85,7 +81,7 @@ LL | #[derive(Dlone)]
8581
::: $SRC_DIR/libcore/clone.rs:LL:COL
8682
|
8783
LL | pub macro Clone($item:item) { /* compiler built-in */ }
88-
| ------------------------------------------------------- similarly named derive macro `Clone` defined here
84+
| --------------------------- similarly named derive macro `Clone` defined here
8985

9086
error: cannot find attribute `FooWithLongNan` in this scope
9187
--> $DIR/resolve-error.rs:32:3
@@ -96,28 +92,24 @@ LL | #[FooWithLongNan]
9692
error: cannot find attribute `attr_proc_macra` in this scope
9793
--> $DIR/resolve-error.rs:28:3
9894
|
99-
LL | #[attr_proc_macra]
100-
| ^^^^^^^^^^^^^^^ help: an attribute macro with a similar name exists: `attr_proc_macro`
95+
LL | #[attr_proc_macra]
96+
| ^^^^^^^^^^^^^^^ help: an attribute macro with a similar name exists: `attr_proc_macro`
10197
|
10298
::: $DIR/auxiliary/test-macros.rs:20:1
10399
|
104-
LL | / pub fn empty_attr(_: TokenStream, _: TokenStream) -> TokenStream {
105-
LL | | TokenStream::new()
106-
LL | | }
107-
| |_- similarly named attribute macro `attr_proc_macro` defined here
100+
LL | pub fn empty_attr(_: TokenStream, _: TokenStream) -> TokenStream {
101+
| ---------------------------------------------------------------- similarly named attribute macro `attr_proc_macro` defined here
108102

109103
error: cannot find derive macro `FooWithLongNan` in this scope
110104
--> $DIR/resolve-error.rs:22:10
111105
|
112-
LL | #[derive(FooWithLongNan)]
113-
| ^^^^^^^^^^^^^^ help: a derive macro with a similar name exists: `FooWithLongName`
106+
LL | #[derive(FooWithLongNan)]
107+
| ^^^^^^^^^^^^^^ help: a derive macro with a similar name exists: `FooWithLongName`
114108
|
115109
::: $DIR/auxiliary/derive-foo.rs:11:1
116110
|
117-
LL | / pub fn derive_foo(input: TokenStream) -> TokenStream {
118-
LL | | "".parse().unwrap()
119-
LL | | }
120-
| |_- similarly named derive macro `FooWithLongName` defined here
111+
LL | pub fn derive_foo(input: TokenStream) -> TokenStream {
112+
| ---------------------------------------------------- similarly named derive macro `FooWithLongName` defined here
121113

122114
error: cannot find derive macro `FooWithLongNan` in this scope
123115
--> $DIR/resolve-error.rs:22:10

src/test/ui/resolve/levenshtein.stderr

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,13 @@ LL | type A = Baz; // Misspelled type name.
1616
error[E0412]: cannot find type `Opiton` in this scope
1717
--> $DIR/levenshtein.rs:12:10
1818
|
19-
LL | type B = Opiton<u8>; // Misspelled type name from the prelude.
20-
| ^^^^^^ help: an enum with a similar name exists: `Option`
19+
LL | type B = Opiton<u8>; // Misspelled type name from the prelude.
20+
| ^^^^^^ help: an enum with a similar name exists: `Option`
2121
|
2222
::: $SRC_DIR/libcore/option.rs:LL:COL
2323
|
24-
LL | / pub enum Option<T> {
25-
LL | | /// No value
26-
LL | | #[stable(feature = "rust1", since = "1.0.0")]
27-
LL | | None,
28-
... |
29-
LL | | Some(#[stable(feature = "rust1", since = "1.0.0")] T),
30-
LL | | }
31-
| |_- similarly named enum `Option` defined here
24+
LL | pub enum Option<T> {
25+
| ------------------ similarly named enum `Option` defined here
3226

3327
error[E0412]: cannot find type `Baz` in this scope
3428
--> $DIR/levenshtein.rs:16:14

src/test/ui/suggestions/attribute-typos.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ LL | #[tests]
2222
::: $SRC_DIR/libcore/macros.rs:LL:COL
2323
|
2424
LL | pub macro test($item:item) { /* compiler built-in */ }
25-
| ------------------------------------------------------ similarly named attribute macro `test` defined here
25+
| -------------------------- similarly named attribute macro `test` defined here
2626

2727
error: cannot find attribute `deprcated` in this scope
2828
--> $DIR/attribute-typos.rs:1:3

0 commit comments

Comments
 (0)