Skip to content
Permalink
Browse files

Use `def_span` to minimize definition span to first line when possible

  • Loading branch information
estebank committed Oct 28, 2019
1 parent 39c96a0 commit 8eb7ac561eb42b70bc7db3852c502dd63186a119
@@ -782,7 +782,10 @@ impl<'a> Resolver<'a> {
);
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)),
_ => 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(
@@ -7,7 +7,7 @@ LL | #[derive(Eqr)]
::: $SRC_DIR/libcore/cmp.rs:LL:COL
|
LL | pub macro Eq($item:item) { /* compiler built-in */ }
| ---------------------------------------------------- similarly named derive macro `Eq` defined here
| ------------------------ similarly named derive macro `Eq` defined here

error: cannot find derive macro `Eqr` in this scope
--> $DIR/deriving-meta-unknown-trait.rs:1:10
@@ -1,19 +1,13 @@
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
LL | pub enum Result<T, E> {
| --------------------- similarly named enum `Result` defined here
|
help: try using the variant's enum
|
@@ -63,19 +57,13 @@ 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
LL | pub enum Result<T, E> {
| --------------------- similarly named enum `Result` defined here
|
help: try using the variant's enum
|
@@ -1,17 +1,13 @@
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
LL | pub trait Fn<Args> : FnMut<Args> {
| -------------------------------- similarly named trait `Fn` defined here

error: aborting due to previous error

@@ -1,18 +1,13 @@
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
LL | macro_rules! println {
| -------------------- similarly named macro `println` defined here

error: aborting due to previous error

@@ -7,7 +7,7 @@ LL | inline!();
::: $SRC_DIR/libcore/macros.rs:LL:COL
|
LL | macro_rules! line { () => { /* compiler built-in */ } }
| ------------------------------------------------------- similarly named macro `line` defined here
| ----------------- similarly named macro `line` defined here

error: aborting due to previous error

@@ -7,7 +7,7 @@ LL | macro_two!();
::: $DIR/auxiliary/two_macros.rs:2:1
|
LL | macro_rules! macro_one { () => ("one") }
| ---------------------------------------- similarly named macro `macro_one` defined here
| ---------------------- similarly named macro `macro_one` defined here

error: aborting due to previous error

@@ -1,15 +1,13 @@
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
LL | pub fn empty(_: TokenStream) -> TokenStream {
| ------------------------------------------- similarly named macro `bang_proc_macro` defined here

error: cannot find macro `Dlona` in this scope
--> $DIR/resolve-error.rs:57:5
@@ -60,15 +58,13 @@ 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
LL | pub fn derive_clonea(input: TokenStream) -> TokenStream {
| ------------------------------------------------------- similarly named derive macro `Clona` defined here

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

error: cannot find attribute `FooWithLongNan` in this scope
--> $DIR/resolve-error.rs:32:3
@@ -96,28 +92,24 @@ 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
LL | pub fn empty_attr(_: TokenStream, _: TokenStream) -> TokenStream {
| ---------------------------------------------------------------- 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
LL | pub fn derive_foo(input: TokenStream) -> TokenStream {
| ---------------------------------------------------- similarly named derive macro `FooWithLongName` defined here

error: cannot find derive macro `FooWithLongNan` in this scope
--> $DIR/resolve-error.rs:22:10
@@ -16,19 +16,13 @@ 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
LL | pub enum Option<T> {
| ------------------ similarly named enum `Option` defined here

error[E0412]: cannot find type `Baz` in this scope
--> $DIR/levenshtein.rs:16:14
@@ -22,7 +22,7 @@ LL | #[tests]
::: $SRC_DIR/libcore/macros.rs:LL:COL
|
LL | pub macro test($item:item) { /* compiler built-in */ }
| ------------------------------------------------------ similarly named attribute macro `test` defined here
| -------------------------- similarly named attribute macro `test` defined here

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

0 comments on commit 8eb7ac5

Please sign in to comment.
You can’t perform that action at this time.