Skip to content

Commit

Permalink
Auto merge of #65912 - estebank:variants-orig, r=petrochenkov
Browse files Browse the repository at this point in the history
Point at the span for the definition of crate foreign ADTs

Follow up to #65421. Partially addresses #65386. Blocked on #53081.
  • Loading branch information
bors committed Jan 11, 2020
2 parents 88d1109 + 38a3506 commit 543b7d9
Show file tree
Hide file tree
Showing 28 changed files with 310 additions and 59 deletions.
4 changes: 4 additions & 0 deletions src/librustc_metadata/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,10 @@ impl CStore {
self.get_crate_data(cnum).source.clone()
}

pub fn get_span_untracked(&self, def_id: DefId, sess: &Session) -> Span {
self.get_crate_data(def_id.krate).get_span(def_id.index, sess)
}

pub fn item_generics_num_lifetimes(&self, def_id: DefId, sess: &Session) -> usize {
self.get_crate_data(def_id.krate).get_generics(def_id.index, sess).own_counts().lifetimes
}
Expand Down
12 changes: 9 additions & 3 deletions src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
use rustc_feature::BUILTIN_ATTRIBUTES;
use rustc_hir::def::Namespace::{self, *};
use rustc_hir::def::{self, DefKind, NonMacroAttrKind};
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_span::hygiene::MacroKind;
use rustc_span::source_map::SourceMap;
use rustc_span::symbol::{kw, Symbol};
Expand Down Expand Up @@ -780,8 +780,14 @@ impl<'a> Resolver<'a> {
suggestion.candidate.to_string(),
Applicability::MaybeIncorrect,
);
let def_span =
suggestion.res.opt_def_id().and_then(|def_id| self.definitions.opt_span(def_id));
let def_span = suggestion.res.opt_def_id().and_then(|def_id| match def_id.krate {
LOCAL_CRATE => self.definitions.opt_span(def_id),
_ => Some(
self.session
.source_map()
.def_span(self.cstore().get_span_untracked(def_id, self.session)),
),
});
if let Some(span) = def_span {
err.span_label(
span,
Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/derives/deriving-meta-unknown-trait.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// FIXME: missing sysroot spans (#53081)
// ignore-i586-unknown-linux-gnu
// ignore-i586-unknown-linux-musl
// ignore-i686-unknown-linux-musl
#[derive(Eqr)]
//~^ ERROR cannot find derive macro `Eqr` in this scope
//~| ERROR cannot find derive macro `Eqr` in this scope
Expand Down
14 changes: 12 additions & 2 deletions src/test/ui/derives/deriving-meta-unknown-trait.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
error: cannot find derive macro `Eqr` in this scope
--> $DIR/deriving-meta-unknown-trait.rs:1:10
--> $DIR/deriving-meta-unknown-trait.rs:5:10
|
LL | #[derive(Eqr)]
| ^^^ help: a derive macro with a similar name exists: `Eq`
|
::: $SRC_DIR/libcore/cmp.rs:LL:COL
|
LL | pub macro Eq($item:item) {
| ------------------------ similarly named derive macro `Eq` defined here

error: cannot find derive macro `Eqr` in this scope
--> $DIR/deriving-meta-unknown-trait.rs:1:10
--> $DIR/deriving-meta-unknown-trait.rs:5:10
|
LL | #[derive(Eqr)]
| ^^^ help: a derive macro with a similar name exists: `Eq`
|
::: $SRC_DIR/libcore/cmp.rs:LL:COL
|
LL | pub macro Eq($item:item) {
| ------------------------ similarly named derive macro `Eq` defined here

error: aborting due to 2 previous errors

20 changes: 20 additions & 0 deletions src/test/ui/empty/empty-struct-braces-expr.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ LL | let e1 = Empty1;
| |
| did you mean `Empty1 { /* fields */ }`?
| help: a unit struct with a similar name exists: `XEmpty2`
|
::: $DIR/auxiliary/empty-struct.rs:2:1
|
LL | pub struct XEmpty2;
| ------------------- similarly named unit struct `XEmpty2` defined here

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

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

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

error[E0599]: no variant or associated item named `Empty3` found for enum `empty_struct::XE` in the current scope
--> $DIR/empty-struct-braces-expr.rs:25:19
Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/empty/empty-struct-braces-pat-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ LL | XE::XEmpty3 => ()
| | |
| | help: a unit variant with a similar name exists: `XEmpty4`
| did you mean `XE::XEmpty3 { /* fields */ }`?
|
::: $DIR/auxiliary/empty-struct.rs:7:5
|
LL | XEmpty4,
| ------- similarly named unit variant `XEmpty4` defined here

error: aborting due to 2 previous errors

Expand Down
20 changes: 20 additions & 0 deletions src/test/ui/empty/empty-struct-braces-pat-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ LL | Empty1() => ()
| |
| did you mean `Empty1 { /* fields */ }`?
| help: a tuple struct with a similar name exists: `XEmpty6`
|
::: $DIR/auxiliary/empty-struct.rs:3:1
|
LL | pub struct XEmpty6();
| --------------------- similarly named tuple struct `XEmpty6` defined here

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

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

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

error: aborting due to 4 previous errors

Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/empty/empty-struct-braces-pat-3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ LL | XE::XEmpty3() => ()
| | |
| | help: a tuple variant with a similar name exists: `XEmpty5`
| did you mean `XE::XEmpty3 { /* fields */ }`?
|
::: $DIR/auxiliary/empty-struct.rs:8:5
|
LL | XEmpty5(),
| --------- similarly named tuple variant `XEmpty5` defined here

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

error: aborting due to 4 previous errors

Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/empty/empty-struct-tuple-pat.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ LL | XE::XEmpty5 => (),
| | |
| | help: a unit variant with a similar name exists: `XEmpty4`
| did you mean `XE::XEmpty5( /* fields */ )`?
|
::: $DIR/auxiliary/empty-struct.rs:7:5
|
LL | XEmpty4,
| ------- similarly named unit variant `XEmpty4` defined here

error: aborting due to 4 previous errors

Expand Down
30 changes: 30 additions & 0 deletions src/test/ui/empty/empty-struct-unit-pat.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,44 @@ error[E0532]: expected tuple struct or tuple variant, found unit struct `Empty2`
|
LL | Empty2() => ()
| ^^^^^^ help: a tuple struct with a similar name exists: `XEmpty6`
|
::: $DIR/auxiliary/empty-struct.rs:3:1
|
LL | pub struct XEmpty6();
| --------------------- similarly named tuple struct `XEmpty6` defined here

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

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

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

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

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

error: aborting due to 8 previous errors

Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/issues/issue-17546.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// FIXME: missing sysroot spans (#53081)
// ignore-i586-unknown-linux-gnu
// ignore-i586-unknown-linux-musl
// ignore-i686-unknown-linux-musl
use foo::MyEnum::Result;
use foo::NoResult; // Through a re-export

Expand Down
18 changes: 14 additions & 4 deletions src/test/ui/issues/issue-17546.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
error[E0573]: expected type, found variant `NoResult`
--> $DIR/issue-17546.rs:12:17
--> $DIR/issue-17546.rs:16:17
|
LL | fn new() -> NoResult<MyEnum, String> {
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
::: $SRC_DIR/libcore/result.rs:LL:COL
|
LL | pub enum Result<T, E> {
| --------------------- similarly named enum `Result` defined here
|
help: try using the variant's enum
|
Expand All @@ -14,7 +19,7 @@ LL | fn new() -> Result<MyEnum, String> {
| ^^^^^^

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

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

error[E0573]: expected type, found variant `NoResult`
--> $DIR/issue-17546.rs:33:15
--> $DIR/issue-17546.rs:37:15
|
LL | fn newer() -> NoResult<foo::MyEnum, String> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
::: $SRC_DIR/libcore/result.rs:LL:COL
|
LL | pub enum Result<T, E> {
| --------------------- similarly named enum `Result` defined here
|
help: try using the variant's enum
|
Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/issues/issue-7607-1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// FIXME: missing sysroot spans (#53081)
// ignore-i586-unknown-linux-gnu
// ignore-i586-unknown-linux-musl
// ignore-i686-unknown-linux-musl
struct Foo {
x: isize
}
Expand Down
7 changes: 6 additions & 1 deletion src/test/ui/issues/issue-7607-1.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
error[E0412]: cannot find type `Fo` in this scope
--> $DIR/issue-7607-1.rs:5:6
--> $DIR/issue-7607-1.rs:9:6
|
LL | impl Fo {
| ^^ help: a trait with a similar name exists: `Fn`
|
::: $SRC_DIR/libcore/ops/function.rs:LL:COL
|
LL | pub trait Fn<Args>: FnMut<Args> {
| ------------------------------- similarly named trait `Fn` defined here

error: aborting due to previous error

Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/macros/macro-name-typo.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// FIXME: missing sysroot spans (#53081)
// ignore-i586-unknown-linux-gnu
// ignore-i586-unknown-linux-musl
// ignore-i686-unknown-linux-musl
fn main() {
printlx!("oh noes!"); //~ ERROR cannot find
}
7 changes: 6 additions & 1 deletion src/test/ui/macros/macro-name-typo.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
error: cannot find macro `printlx` in this scope
--> $DIR/macro-name-typo.rs:2:5
--> $DIR/macro-name-typo.rs:6:5
|
LL | printlx!("oh noes!");
| ^^^^^^^ help: a macro with a similar name exists: `println`
|
::: $SRC_DIR/libstd/macros.rs:LL:COL
|
LL | macro_rules! println {
| -------------------- similarly named macro `println` defined here

error: aborting due to previous error

4 changes: 4 additions & 0 deletions src/test/ui/macros/macro-path-prelude-fail-3.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// FIXME: missing sysroot spans (#53081)
// ignore-i586-unknown-linux-gnu
// ignore-i586-unknown-linux-musl
// ignore-i686-unknown-linux-musl
fn main() {
inline!(); //~ ERROR cannot find macro `inline` in this scope
}
Loading

0 comments on commit 543b7d9

Please sign in to comment.