Point at the span for the definition of crate foreign ADTs

This commit is contained in:
Esteban Küber 2019-10-14 17:20:50 -07:00
parent f795e8a216
commit 39c96a0f53
19 changed files with 247 additions and 21 deletions

View file

@ -479,6 +479,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
}

View file

@ -9,7 +9,7 @@ use rustc_data_structures::fx::FxHashSet;
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};
@ -780,8 +780,10 @@ 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.cstore().get_span_untracked(def_id, self.session)),
});
if let Some(span) = def_span {
err.span_label(
span,

View file

@ -3,6 +3,11 @@ error: cannot find derive macro `Eqr` in this scope
|
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) { /* compiler built-in */ }
| ---------------------------------------------------- similarly named derive macro `Eq` defined here
error: cannot find derive macro `Eqr` in this scope
--> $DIR/deriving-meta-unknown-trait.rs:1:10

View file

@ -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
@ -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
@ -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
@ -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 type `empty_struct::XE` in the current scope
--> $DIR/empty-struct-braces-expr.rs:25:19

View file

@ -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

View file

@ -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
@ -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
@ -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
@ -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

View file

@ -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
@ -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

View file

@ -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

View file

@ -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
@ -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
@ -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

View file

@ -1,8 +1,19 @@
error[E0573]: expected type, found variant `NoResult`
--> $DIR/issue-17546.rs:12:17
|
LL | fn new() -> NoResult<MyEnum, String> {
| ^^^^^^^^^^^^^^^^^^^^^^^^
LL | fn new() -> NoResult<MyEnum, String> {
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
::: $SRC_DIR/libcore/result.rs:LL:COL
|
LL | / pub enum Result<T, E> {
LL | | /// Contains the success value
LL | | #[stable(feature = "rust1", since = "1.0.0")]
LL | | Ok(#[stable(feature = "rust1", since = "1.0.0")] T),
... |
LL | | Err(#[stable(feature = "rust1", since = "1.0.0")] E),
LL | | }
| |_- similarly named enum `Result` defined here
|
help: try using the variant's enum
|
@ -52,8 +63,19 @@ LL | use std::result::Result;
error[E0573]: expected type, found variant `NoResult`
--> $DIR/issue-17546.rs:33:15
|
LL | fn newer() -> NoResult<foo::MyEnum, String> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | fn newer() -> NoResult<foo::MyEnum, String> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
::: $SRC_DIR/libcore/result.rs:LL:COL
|
LL | / pub enum Result<T, E> {
LL | | /// Contains the success value
LL | | #[stable(feature = "rust1", since = "1.0.0")]
LL | | Ok(#[stable(feature = "rust1", since = "1.0.0")] T),
... |
LL | | Err(#[stable(feature = "rust1", since = "1.0.0")] E),
LL | | }
| |_- similarly named enum `Result` defined here
|
help: try using the variant's enum
|

View file

@ -1,8 +1,17 @@
error[E0412]: cannot find type `Fo` in this scope
--> $DIR/issue-7607-1.rs:5:6
|
LL | impl Fo {
| ^^ help: a trait with a similar name exists: `Fn`
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> {
LL | | /// Performs the call operation.
LL | | #[unstable(feature = "fn_traits", issue = "29625")]
LL | | extern "rust-call" fn call(&self, args: Args) -> Self::Output;
LL | | }
| |_- similarly named trait `Fn` defined here
error: aborting due to previous error

View file

@ -1,8 +1,18 @@
error: cannot find macro `printlx` in this scope
--> $DIR/macro-name-typo.rs:2:5
|
LL | printlx!("oh noes!");
| ^^^^^^^ help: a macro with a similar name exists: `println`
LL | printlx!("oh noes!");
| ^^^^^^^ help: a macro with a similar name exists: `println`
|
::: $SRC_DIR/libstd/macros.rs:LL:COL
|
LL | / macro_rules! println {
LL | | () => ($crate::print!("\n"));
LL | | ($($arg:tt)*) => ({
LL | | $crate::io::_print($crate::format_args_nl!($($arg)*));
LL | | })
LL | | }
| |_- similarly named macro `println` defined here
error: aborting due to previous error

View file

@ -3,6 +3,11 @@ error: cannot find macro `inline` in this scope
|
LL | inline!();
| ^^^^^^ help: a macro with a similar name exists: `line`
|
::: $SRC_DIR/libcore/macros.rs:LL:COL
|
LL | macro_rules! line { () => { /* compiler built-in */ } }
| ------------------------------------------------------- similarly named macro `line` defined here
error: aborting due to previous error

View file

@ -3,6 +3,11 @@ error: cannot find macro `macro_two` in this scope
|
LL | macro_two!();
| ^^^^^^^^^ help: a macro with a similar name exists: `macro_one`
|
::: $DIR/auxiliary/two_macros.rs:2:1
|
LL | macro_rules! macro_one { () => ("one") }
| ---------------------------------------- similarly named macro `macro_one` defined here
error: aborting due to previous error

View file

@ -24,6 +24,11 @@ error[E0423]: expected value, found type alias `xm1::S`
|
LL | check(xm1::S);
| ^^^^^^
|
::: $DIR/auxiliary/namespace-mix.rs:3:5
|
LL | pub struct TS();
| ---------------- similarly named tuple struct `TS` defined here
|
= note: can't use a type alias as a constructor
help: a tuple struct with a similar name exists
@ -64,6 +69,11 @@ error[E0423]: expected value, found struct variant `xm7::V`
|
LL | check(xm7::V);
| ^^^^^^ did you mean `xm7::V { /* fields */ }`?
|
::: $DIR/auxiliary/namespace-mix.rs:7:9
|
LL | TV(),
| ---- similarly named tuple variant `TV` defined here
|
help: a tuple variant with a similar name exists
|

View file

@ -132,6 +132,11 @@ LL | parent_source_spans!($($tokens)*);
...
LL | one!("hello", "world");
| ----------------------- in this macro invocation
|
::: $SRC_DIR/libcore/result.rs:LL:COL
|
LL | Ok(#[stable(feature = "rust1", since = "1.0.0")] T),
| --------------------------------------------------- similarly named tuple variant `Ok` defined here
error[E0425]: cannot find value `ok` in this scope
--> $DIR/parent-source-spans.rs:28:5
@ -141,6 +146,11 @@ LL | parent_source_spans!($($tokens)*);
...
LL | two!("yay", "rust");
| -------------------- in this macro invocation
|
::: $SRC_DIR/libcore/result.rs:LL:COL
|
LL | Ok(#[stable(feature = "rust1", since = "1.0.0")] T),
| --------------------------------------------------- similarly named tuple variant `Ok` defined here
error[E0425]: cannot find value `ok` in this scope
--> $DIR/parent-source-spans.rs:28:5
@ -150,6 +160,11 @@ LL | parent_source_spans!($($tokens)*);
...
LL | three!("hip", "hop");
| --------------------- in this macro invocation
|
::: $SRC_DIR/libcore/result.rs:LL:COL
|
LL | Ok(#[stable(feature = "rust1", since = "1.0.0")] T),
| --------------------------------------------------- similarly named tuple variant `Ok` defined here
error: aborting due to 21 previous errors

View file

@ -1,8 +1,15 @@
error: cannot find macro `bang_proc_macrp` in this scope
--> $DIR/resolve-error.rs:60:5
|
LL | bang_proc_macrp!();
| ^^^^^^^^^^^^^^^ help: a macro with a similar name exists: `bang_proc_macro`
LL | bang_proc_macrp!();
| ^^^^^^^^^^^^^^^ help: a macro with a similar name exists: `bang_proc_macro`
|
::: $DIR/auxiliary/test-macros.rs:15:1
|
LL | / pub fn empty(_: TokenStream) -> TokenStream {
LL | | TokenStream::new()
LL | | }
| |_- similarly named macro `bang_proc_macro` defined here
error: cannot find macro `Dlona` in this scope
--> $DIR/resolve-error.rs:57:5
@ -53,8 +60,15 @@ LL | #[derive(Dlona)]
error: cannot find derive macro `Dlona` in this scope
--> $DIR/resolve-error.rs:40:10
|
LL | #[derive(Dlona)]
| ^^^^^ help: a derive macro with a similar name exists: `Clona`
LL | #[derive(Dlona)]
| ^^^^^ help: a derive macro with a similar name exists: `Clona`
|
::: $DIR/auxiliary/derive-clona.rs:11:1
|
LL | / pub fn derive_clonea(input: TokenStream) -> TokenStream {
LL | | "".parse().unwrap()
LL | | }
| |_- similarly named derive macro `Clona` defined here
error: cannot find derive macro `Dlone` in this scope
--> $DIR/resolve-error.rs:35:10
@ -67,6 +81,11 @@ error: cannot find derive macro `Dlone` in this scope
|
LL | #[derive(Dlone)]
| ^^^^^ help: a derive macro with a similar name exists: `Clone`
|
::: $SRC_DIR/libcore/clone.rs:LL:COL
|
LL | pub macro Clone($item:item) { /* compiler built-in */ }
| ------------------------------------------------------- similarly named derive macro `Clone` defined here
error: cannot find attribute `FooWithLongNan` in this scope
--> $DIR/resolve-error.rs:32:3
@ -77,14 +96,28 @@ LL | #[FooWithLongNan]
error: cannot find attribute `attr_proc_macra` in this scope
--> $DIR/resolve-error.rs:28:3
|
LL | #[attr_proc_macra]
| ^^^^^^^^^^^^^^^ help: an attribute macro with a similar name exists: `attr_proc_macro`
LL | #[attr_proc_macra]
| ^^^^^^^^^^^^^^^ help: an attribute macro with a similar name exists: `attr_proc_macro`
|
::: $DIR/auxiliary/test-macros.rs:20:1
|
LL | / pub fn empty_attr(_: TokenStream, _: TokenStream) -> TokenStream {
LL | | TokenStream::new()
LL | | }
| |_- similarly named attribute macro `attr_proc_macro` defined here
error: cannot find derive macro `FooWithLongNan` in this scope
--> $DIR/resolve-error.rs:22:10
|
LL | #[derive(FooWithLongNan)]
| ^^^^^^^^^^^^^^ help: a derive macro with a similar name exists: `FooWithLongName`
LL | #[derive(FooWithLongNan)]
| ^^^^^^^^^^^^^^ help: a derive macro with a similar name exists: `FooWithLongName`
|
::: $DIR/auxiliary/derive-foo.rs:11:1
|
LL | / pub fn derive_foo(input: TokenStream) -> TokenStream {
LL | | "".parse().unwrap()
LL | | }
| |_- similarly named derive macro `FooWithLongName` defined here
error: cannot find derive macro `FooWithLongNan` in this scope
--> $DIR/resolve-error.rs:22:10

View file

@ -16,8 +16,19 @@ LL | type A = Baz; // Misspelled type name.
error[E0412]: cannot find type `Opiton` in this scope
--> $DIR/levenshtein.rs:12:10
|
LL | type B = Opiton<u8>; // Misspelled type name from the prelude.
| ^^^^^^ help: an enum with a similar name exists: `Option`
LL | type B = Opiton<u8>; // Misspelled type name from the prelude.
| ^^^^^^ help: an enum with a similar name exists: `Option`
|
::: $SRC_DIR/libcore/option.rs:LL:COL
|
LL | / pub enum Option<T> {
LL | | /// No value
LL | | #[stable(feature = "rust1", since = "1.0.0")]
LL | | None,
... |
LL | | Some(#[stable(feature = "rust1", since = "1.0.0")] T),
LL | | }
| |_- similarly named enum `Option` defined here
error[E0412]: cannot find type `Baz` in this scope
--> $DIR/levenshtein.rs:16:14

View file

@ -18,6 +18,11 @@ error: cannot find attribute `tests` in this scope
|
LL | #[tests]
| ^^^^^ help: an attribute macro with a similar name exists: `test`
|
::: $SRC_DIR/libcore/macros.rs:LL:COL
|
LL | pub macro test($item:item) { /* compiler built-in */ }
| ------------------------------------------------------ similarly named attribute macro `test` defined here
error: cannot find attribute `deprcated` in this scope
--> $DIR/attribute-typos.rs:1:3