Skip to content

Commit 39c96a0

Browse files
committed
Point at the span for the definition of crate foreign ADTs
1 parent f795e8a commit 39c96a0

19 files changed

+247
-21
lines changed

src/librustc_metadata/rmeta/decoder/cstore_impl.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,10 @@ impl CStore {
479479
self.get_crate_data(cnum).source.clone()
480480
}
481481

482+
pub fn get_span_untracked(&self, def_id: DefId, sess: &Session) -> Span {
483+
self.get_crate_data(def_id.krate).get_span(def_id.index, sess)
484+
}
485+
482486
pub fn item_generics_num_lifetimes(&self, def_id: DefId, sess: &Session) -> usize {
483487
self.get_crate_data(def_id.krate).get_generics(def_id.index, sess).own_counts().lifetimes
484488
}

src/librustc_resolve/diagnostics.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_data_structures::fx::FxHashSet;
99
use rustc_feature::BUILTIN_ATTRIBUTES;
1010
use rustc_hir::def::Namespace::{self, *};
1111
use rustc_hir::def::{self, DefKind, NonMacroAttrKind};
12-
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
12+
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
1313
use rustc_span::hygiene::MacroKind;
1414
use rustc_span::source_map::SourceMap;
1515
use rustc_span::symbol::{kw, Symbol};
@@ -780,8 +780,10 @@ impl<'a> Resolver<'a> {
780780
suggestion.candidate.to_string(),
781781
Applicability::MaybeIncorrect,
782782
);
783-
let def_span =
784-
suggestion.res.opt_def_id().and_then(|def_id| self.definitions.opt_span(def_id));
783+
let def_span = suggestion.res.opt_def_id().and_then(|def_id| match def_id.krate {
784+
LOCAL_CRATE => self.definitions.opt_span(def_id),
785+
_ => Some(self.cstore().get_span_untracked(def_id, self.session)),
786+
});
785787
if let Some(span) = def_span {
786788
err.span_label(
787789
span,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ error: cannot find derive macro `Eqr` in this scope
33
|
44
LL | #[derive(Eqr)]
55
| ^^^ help: a derive macro with a similar name exists: `Eq`
6+
|
7+
::: $SRC_DIR/libcore/cmp.rs:LL:COL
8+
|
9+
LL | pub macro Eq($item:item) { /* compiler built-in */ }
10+
| ---------------------------------------------------- similarly named derive macro `Eq` defined here
611

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

src/test/ui/empty/empty-struct-braces-expr.stderr

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ LL | let e1 = Empty1;
99
| |
1010
| did you mean `Empty1 { /* fields */ }`?
1111
| help: a unit struct with a similar name exists: `XEmpty2`
12+
|
13+
::: $DIR/auxiliary/empty-struct.rs:2:1
14+
|
15+
LL | pub struct XEmpty2;
16+
| ------------------- similarly named unit struct `XEmpty2` defined here
1217

1318
error[E0423]: expected function, tuple struct or tuple variant, found struct `Empty1`
1419
--> $DIR/empty-struct-braces-expr.rs:16:14
@@ -21,6 +26,11 @@ LL | let e1 = Empty1();
2126
| |
2227
| did you mean `Empty1 { /* fields */ }`?
2328
| help: a unit struct with a similar name exists: `XEmpty2`
29+
|
30+
::: $DIR/auxiliary/empty-struct.rs:2:1
31+
|
32+
LL | pub struct XEmpty2;
33+
| ------------------- similarly named unit struct `XEmpty2` defined here
2434

2535
error[E0423]: expected value, found struct variant `E::Empty3`
2636
--> $DIR/empty-struct-braces-expr.rs:18:14
@@ -48,6 +58,11 @@ LL | let xe1 = XEmpty1;
4858
| |
4959
| did you mean `XEmpty1 { /* fields */ }`?
5060
| help: a unit struct with a similar name exists: `XEmpty2`
61+
|
62+
::: $DIR/auxiliary/empty-struct.rs:2:1
63+
|
64+
LL | pub struct XEmpty2;
65+
| ------------------- similarly named unit struct `XEmpty2` defined here
5166

5267
error[E0423]: expected function, tuple struct or tuple variant, found struct `XEmpty1`
5368
--> $DIR/empty-struct-braces-expr.rs:23:15
@@ -57,6 +72,11 @@ LL | let xe1 = XEmpty1();
5772
| |
5873
| did you mean `XEmpty1 { /* fields */ }`?
5974
| help: a unit struct with a similar name exists: `XEmpty2`
75+
|
76+
::: $DIR/auxiliary/empty-struct.rs:2:1
77+
|
78+
LL | pub struct XEmpty2;
79+
| ------------------- similarly named unit struct `XEmpty2` defined here
6080

6181
error[E0599]: no variant or associated item named `Empty3` found for type `empty_struct::XE` in the current scope
6282
--> $DIR/empty-struct-braces-expr.rs:25:19

src/test/ui/empty/empty-struct-braces-pat-1.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ LL | XE::XEmpty3 => ()
1515
| | |
1616
| | help: a unit variant with a similar name exists: `XEmpty4`
1717
| did you mean `XE::XEmpty3 { /* fields */ }`?
18+
|
19+
::: $DIR/auxiliary/empty-struct.rs:7:5
20+
|
21+
LL | XEmpty4,
22+
| ------- similarly named unit variant `XEmpty4` defined here
1823

1924
error: aborting due to 2 previous errors
2025

src/test/ui/empty/empty-struct-braces-pat-2.stderr

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ LL | Empty1() => ()
99
| |
1010
| did you mean `Empty1 { /* fields */ }`?
1111
| help: a tuple struct with a similar name exists: `XEmpty6`
12+
|
13+
::: $DIR/auxiliary/empty-struct.rs:3:1
14+
|
15+
LL | pub struct XEmpty6();
16+
| --------------------- similarly named tuple struct `XEmpty6` defined here
1217

1318
error[E0532]: expected tuple struct or tuple variant, found struct `XEmpty1`
1419
--> $DIR/empty-struct-braces-pat-2.rs:18:9
@@ -18,6 +23,11 @@ LL | XEmpty1() => ()
1823
| |
1924
| did you mean `XEmpty1 { /* fields */ }`?
2025
| help: a tuple struct with a similar name exists: `XEmpty6`
26+
|
27+
::: $DIR/auxiliary/empty-struct.rs:3:1
28+
|
29+
LL | pub struct XEmpty6();
30+
| --------------------- similarly named tuple struct `XEmpty6` defined here
2131

2232
error[E0532]: expected tuple struct or tuple variant, found struct `Empty1`
2333
--> $DIR/empty-struct-braces-pat-2.rs:21:9
@@ -30,6 +40,11 @@ LL | Empty1(..) => ()
3040
| |
3141
| did you mean `Empty1 { /* fields */ }`?
3242
| help: a tuple struct with a similar name exists: `XEmpty6`
43+
|
44+
::: $DIR/auxiliary/empty-struct.rs:3:1
45+
|
46+
LL | pub struct XEmpty6();
47+
| --------------------- similarly named tuple struct `XEmpty6` defined here
3348

3449
error[E0532]: expected tuple struct or tuple variant, found struct `XEmpty1`
3550
--> $DIR/empty-struct-braces-pat-2.rs:24:9
@@ -39,6 +54,11 @@ LL | XEmpty1(..) => ()
3954
| |
4055
| did you mean `XEmpty1 { /* fields */ }`?
4156
| help: a tuple struct with a similar name exists: `XEmpty6`
57+
|
58+
::: $DIR/auxiliary/empty-struct.rs:3:1
59+
|
60+
LL | pub struct XEmpty6();
61+
| --------------------- similarly named tuple struct `XEmpty6` defined here
4262

4363
error: aborting due to 4 previous errors
4464

src/test/ui/empty/empty-struct-braces-pat-3.stderr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ LL | XE::XEmpty3() => ()
1515
| | |
1616
| | help: a tuple variant with a similar name exists: `XEmpty5`
1717
| did you mean `XE::XEmpty3 { /* fields */ }`?
18+
|
19+
::: $DIR/auxiliary/empty-struct.rs:8:5
20+
|
21+
LL | XEmpty5(),
22+
| --------- similarly named tuple variant `XEmpty5` defined here
1823

1924
error[E0532]: expected tuple struct or tuple variant, found struct variant `E::Empty3`
2025
--> $DIR/empty-struct-braces-pat-3.rs:25:9
@@ -33,6 +38,11 @@ LL | XE::XEmpty3(..) => ()
3338
| | |
3439
| | help: a tuple variant with a similar name exists: `XEmpty5`
3540
| did you mean `XE::XEmpty3 { /* fields */ }`?
41+
|
42+
::: $DIR/auxiliary/empty-struct.rs:8:5
43+
|
44+
LL | XEmpty5(),
45+
| --------- similarly named tuple variant `XEmpty5` defined here
3646

3747
error: aborting due to 4 previous errors
3848

src/test/ui/empty/empty-struct-tuple-pat.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ LL | XE::XEmpty5 => (),
3333
| | |
3434
| | help: a unit variant with a similar name exists: `XEmpty4`
3535
| did you mean `XE::XEmpty5( /* fields */ )`?
36+
|
37+
::: $DIR/auxiliary/empty-struct.rs:7:5
38+
|
39+
LL | XEmpty4,
40+
| ------- similarly named unit variant `XEmpty4` defined here
3641

3742
error: aborting due to 4 previous errors
3843

src/test/ui/empty/empty-struct-unit-pat.stderr

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,44 @@ error[E0532]: expected tuple struct or tuple variant, found unit struct `Empty2`
33
|
44
LL | Empty2() => ()
55
| ^^^^^^ help: a tuple struct with a similar name exists: `XEmpty6`
6+
|
7+
::: $DIR/auxiliary/empty-struct.rs:3:1
8+
|
9+
LL | pub struct XEmpty6();
10+
| --------------------- similarly named tuple struct `XEmpty6` defined here
611

712
error[E0532]: expected tuple struct or tuple variant, found unit struct `XEmpty2`
813
--> $DIR/empty-struct-unit-pat.rs:24:9
914
|
1015
LL | XEmpty2() => ()
1116
| ^^^^^^^ help: a tuple struct with a similar name exists: `XEmpty6`
17+
|
18+
::: $DIR/auxiliary/empty-struct.rs:3:1
19+
|
20+
LL | pub struct XEmpty6();
21+
| --------------------- similarly named tuple struct `XEmpty6` defined here
1222

1323
error[E0532]: expected tuple struct or tuple variant, found unit struct `Empty2`
1424
--> $DIR/empty-struct-unit-pat.rs:28:9
1525
|
1626
LL | Empty2(..) => ()
1727
| ^^^^^^ help: a tuple struct with a similar name exists: `XEmpty6`
28+
|
29+
::: $DIR/auxiliary/empty-struct.rs:3:1
30+
|
31+
LL | pub struct XEmpty6();
32+
| --------------------- similarly named tuple struct `XEmpty6` defined here
1833

1934
error[E0532]: expected tuple struct or tuple variant, found unit struct `XEmpty2`
2035
--> $DIR/empty-struct-unit-pat.rs:32:9
2136
|
2237
LL | XEmpty2(..) => ()
2338
| ^^^^^^^ help: a tuple struct with a similar name exists: `XEmpty6`
39+
|
40+
::: $DIR/auxiliary/empty-struct.rs:3:1
41+
|
42+
LL | pub struct XEmpty6();
43+
| --------------------- similarly named tuple struct `XEmpty6` defined here
2444

2545
error[E0532]: expected tuple struct or tuple variant, found unit variant `E::Empty4`
2646
--> $DIR/empty-struct-unit-pat.rs:37:9
@@ -35,6 +55,11 @@ LL | XE::XEmpty4() => (),
3555
| ^^^^-------
3656
| |
3757
| help: a tuple variant with a similar name exists: `XEmpty5`
58+
|
59+
::: $DIR/auxiliary/empty-struct.rs:8:5
60+
|
61+
LL | XEmpty5(),
62+
| --------- similarly named tuple variant `XEmpty5` defined here
3863

3964
error[E0532]: expected tuple struct or tuple variant, found unit variant `E::Empty4`
4065
--> $DIR/empty-struct-unit-pat.rs:46:9
@@ -49,6 +74,11 @@ LL | XE::XEmpty4(..) => (),
4974
| ^^^^-------
5075
| |
5176
| help: a tuple variant with a similar name exists: `XEmpty5`
77+
|
78+
::: $DIR/auxiliary/empty-struct.rs:8:5
79+
|
80+
LL | XEmpty5(),
81+
| --------- similarly named tuple variant `XEmpty5` defined here
5282

5383
error: aborting due to 8 previous errors
5484

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
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+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
::: $SRC_DIR/libcore/result.rs:LL:COL
8+
|
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
617
|
718
help: try using the variant's enum
819
|
@@ -52,8 +63,19 @@ LL | use std::result::Result;
5263
error[E0573]: expected type, found variant `NoResult`
5364
--> $DIR/issue-17546.rs:33:15
5465
|
55-
LL | fn newer() -> NoResult<foo::MyEnum, String> {
56-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66+
LL | fn newer() -> NoResult<foo::MyEnum, String> {
67+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
68+
|
69+
::: $SRC_DIR/libcore/result.rs:LL:COL
70+
|
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
5779
|
5880
help: try using the variant's enum
5981
|

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
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`
6+
|
7+
::: $SRC_DIR/libcore/ops/function.rs:LL:COL
8+
|
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
615

716
error: aborting due to previous error
817

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
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`
6+
|
7+
::: $SRC_DIR/libstd/macros.rs:LL:COL
8+
|
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
616

717
error: aborting due to previous error
818

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ error: cannot find macro `inline` in this scope
33
|
44
LL | inline!();
55
| ^^^^^^ help: a macro with a similar name exists: `line`
6+
|
7+
::: $SRC_DIR/libcore/macros.rs:LL:COL
8+
|
9+
LL | macro_rules! line { () => { /* compiler built-in */ } }
10+
| ------------------------------------------------------- similarly named macro `line` defined here
611

712
error: aborting due to previous error
813

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ error: cannot find macro `macro_two` in this scope
33
|
44
LL | macro_two!();
55
| ^^^^^^^^^ help: a macro with a similar name exists: `macro_one`
6+
|
7+
::: $DIR/auxiliary/two_macros.rs:2:1
8+
|
9+
LL | macro_rules! macro_one { () => ("one") }
10+
| ---------------------------------------- similarly named macro `macro_one` defined here
611

712
error: aborting due to previous error
813

src/test/ui/namespace/namespace-mix.stderr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ error[E0423]: expected value, found type alias `xm1::S`
2424
|
2525
LL | check(xm1::S);
2626
| ^^^^^^
27+
|
28+
::: $DIR/auxiliary/namespace-mix.rs:3:5
29+
|
30+
LL | pub struct TS();
31+
| ---------------- similarly named tuple struct `TS` defined here
2732
|
2833
= note: can't use a type alias as a constructor
2934
help: a tuple struct with a similar name exists
@@ -64,6 +69,11 @@ error[E0423]: expected value, found struct variant `xm7::V`
6469
|
6570
LL | check(xm7::V);
6671
| ^^^^^^ did you mean `xm7::V { /* fields */ }`?
72+
|
73+
::: $DIR/auxiliary/namespace-mix.rs:7:9
74+
|
75+
LL | TV(),
76+
| ---- similarly named tuple variant `TV` defined here
6777
|
6878
help: a tuple variant with a similar name exists
6979
|

0 commit comments

Comments
 (0)