Skip to content

Commit 543b7d9

Browse files
committed
Auto merge of rust-lang#65912 - estebank:variants-orig, r=petrochenkov
Point at the span for the definition of crate foreign ADTs Follow up to rust-lang#65421. Partially addresses rust-lang#65386. Blocked on rust-lang#53081.
2 parents 88d1109 + 38a3506 commit 543b7d9

28 files changed

+310
-59
lines changed

src/librustc_metadata/rmeta/decoder/cstore_impl.rs

+4
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,10 @@ impl CStore {
478478
self.get_crate_data(cnum).source.clone()
479479
}
480480

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

src/librustc_resolve/diagnostics.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
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,14 @@ 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(
786+
self.session
787+
.source_map()
788+
.def_span(self.cstore().get_span_untracked(def_id, self.session)),
789+
),
790+
});
785791
if let Some(span) = def_span {
786792
err.span_label(
787793
span,

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

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// FIXME: missing sysroot spans (#53081)
2+
// ignore-i586-unknown-linux-gnu
3+
// ignore-i586-unknown-linux-musl
4+
// ignore-i686-unknown-linux-musl
15
#[derive(Eqr)]
26
//~^ ERROR cannot find derive macro `Eqr` in this scope
37
//~| ERROR cannot find derive macro `Eqr` in this scope
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
error: cannot find derive macro `Eqr` in this scope
2-
--> $DIR/deriving-meta-unknown-trait.rs:1:10
2+
--> $DIR/deriving-meta-unknown-trait.rs:5:10
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) {
10+
| ------------------------ similarly named derive macro `Eq` defined here
611

712
error: cannot find derive macro `Eqr` in this scope
8-
--> $DIR/deriving-meta-unknown-trait.rs:1:10
13+
--> $DIR/deriving-meta-unknown-trait.rs:5:10
914
|
1015
LL | #[derive(Eqr)]
1116
| ^^^ help: a derive macro with a similar name exists: `Eq`
17+
|
18+
::: $SRC_DIR/libcore/cmp.rs:LL:COL
19+
|
20+
LL | pub macro Eq($item:item) {
21+
| ------------------------ similarly named derive macro `Eq` defined here
1222

1323
error: aborting due to 2 previous errors
1424

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

+20
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 enum `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

+5
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

+20
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

+10
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

+5
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

+30
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.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// FIXME: missing sysroot spans (#53081)
2+
// ignore-i586-unknown-linux-gnu
3+
// ignore-i586-unknown-linux-musl
4+
// ignore-i686-unknown-linux-musl
15
use foo::MyEnum::Result;
26
use foo::NoResult; // Through a re-export
37

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

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
error[E0573]: expected type, found variant `NoResult`
2-
--> $DIR/issue-17546.rs:12:17
2+
--> $DIR/issue-17546.rs:16:17
33
|
44
LL | fn new() -> NoResult<MyEnum, String> {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
::: $SRC_DIR/libcore/result.rs:LL:COL
8+
|
9+
LL | pub enum Result<T, E> {
10+
| --------------------- similarly named enum `Result` defined here
611
|
712
help: try using the variant's enum
813
|
@@ -14,7 +19,7 @@ LL | fn new() -> Result<MyEnum, String> {
1419
| ^^^^^^
1520

1621
error[E0573]: expected type, found variant `Result`
17-
--> $DIR/issue-17546.rs:22:17
22+
--> $DIR/issue-17546.rs:26:17
1823
|
1924
LL | fn new() -> Result<foo::MyEnum, String> {
2025
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a type
@@ -32,7 +37,7 @@ LL | use std::result::Result;
3237
and 1 other candidate
3338

3439
error[E0573]: expected type, found variant `Result`
35-
--> $DIR/issue-17546.rs:28:13
40+
--> $DIR/issue-17546.rs:32:13
3641
|
3742
LL | fn new() -> Result<foo::MyEnum, String> {
3843
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a type
@@ -50,10 +55,15 @@ LL | use std::result::Result;
5055
and 1 other candidate
5156

5257
error[E0573]: expected type, found variant `NoResult`
53-
--> $DIR/issue-17546.rs:33:15
58+
--> $DIR/issue-17546.rs:37:15
5459
|
5560
LL | fn newer() -> NoResult<foo::MyEnum, String> {
5661
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
62+
|
63+
::: $SRC_DIR/libcore/result.rs:LL:COL
64+
|
65+
LL | pub enum Result<T, E> {
66+
| --------------------- similarly named enum `Result` defined here
5767
|
5868
help: try using the variant's enum
5969
|

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

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// FIXME: missing sysroot spans (#53081)
2+
// ignore-i586-unknown-linux-gnu
3+
// ignore-i586-unknown-linux-musl
4+
// ignore-i686-unknown-linux-musl
15
struct Foo {
26
x: isize
37
}

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
error[E0412]: cannot find type `Fo` in this scope
2-
--> $DIR/issue-7607-1.rs:5:6
2+
--> $DIR/issue-7607-1.rs:9:6
33
|
44
LL | impl Fo {
55
| ^^ 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+
| ------------------------------- similarly named trait `Fn` defined here
611

712
error: aborting due to previous error
813

src/test/ui/macros/macro-name-typo.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// FIXME: missing sysroot spans (#53081)
2+
// ignore-i586-unknown-linux-gnu
3+
// ignore-i586-unknown-linux-musl
4+
// ignore-i686-unknown-linux-musl
15
fn main() {
26
printlx!("oh noes!"); //~ ERROR cannot find
37
}
+6-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
error: cannot find macro `printlx` in this scope
2-
--> $DIR/macro-name-typo.rs:2:5
2+
--> $DIR/macro-name-typo.rs:6:5
33
|
44
LL | printlx!("oh noes!");
55
| ^^^^^^^ 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+
| -------------------- similarly named macro `println` defined here
611

712
error: aborting due to previous error
813

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// FIXME: missing sysroot spans (#53081)
2+
// ignore-i586-unknown-linux-gnu
3+
// ignore-i586-unknown-linux-musl
4+
// ignore-i686-unknown-linux-musl
15
fn main() {
26
inline!(); //~ ERROR cannot find macro `inline` in this scope
37
}

0 commit comments

Comments
 (0)