From af7b8433e7635477f8ebeb13bea10f4d460b399f Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 24 Oct 2022 21:34:39 -0700 Subject: [PATCH 1/2] Remove 'rustc is so bad at spans' workaround --- src/emit.rs | 16 ---------------- tests/ui/let-unstable.stderr | 8 +++----- tests/ui/match-unstable.stderr | 8 +++----- tests/ui/unsorted-match-unstable.stderr | 8 +++----- 4 files changed, 9 insertions(+), 31 deletions(-) diff --git a/src/emit.rs b/src/emit.rs index 9230174..68a24f6 100644 --- a/src/emit.rs +++ b/src/emit.rs @@ -1,5 +1,4 @@ use proc_macro::TokenStream; -use proc_macro2::Span; use quote::quote; use syn::Error; @@ -12,12 +11,6 @@ pub enum Kind { } pub fn emit(err: Error, kind: Kind, output: TokenStream) -> TokenStream { - let mut err = err; - if !probably_has_spans(kind) { - // Otherwise the error is printed without any line number. - err = Error::new(Span::call_site(), err); - } - let err = err.to_compile_error(); let output = proc_macro2::TokenStream::from(output); @@ -28,12 +21,3 @@ pub fn emit(err: Error, kind: Kind, output: TokenStream) -> TokenStream { TokenStream::from(expanded) } - -// Rustc is so bad at spans. -// https://github.com/rust-lang/rust/issues/43081 -fn probably_has_spans(kind: Kind) -> bool { - match kind { - Kind::Enum | Kind::Struct => true, - Kind::Match | Kind::Let => false, - } -} diff --git a/tests/ui/let-unstable.stderr b/tests/ui/let-unstable.stderr index 87f2209..4f5e6ee 100644 --- a/tests/ui/let-unstable.stderr +++ b/tests/ui/let-unstable.stderr @@ -1,7 +1,5 @@ error: E::Bbb should sort before E::Ccc - --> tests/ui/let-unstable.rs:15:5 + --> tests/ui/let-unstable.rs:20:9 | -15 | #[sorted] - | ^^^^^^^^^ - | - = note: this error originates in the attribute macro `sorted` (in Nightly builds, run with -Z macro-backtrace for more info) +20 | E::Bbb(_, _) => {} + | ^^^^^^ diff --git a/tests/ui/match-unstable.stderr b/tests/ui/match-unstable.stderr index acc0378..e406aab 100644 --- a/tests/ui/match-unstable.stderr +++ b/tests/ui/match-unstable.stderr @@ -1,7 +1,5 @@ error: E::Bbb should sort before E::Ccc - --> tests/ui/match-unstable.rs:15:5 + --> tests/ui/match-unstable.rs:20:9 | -15 | #[sorted] - | ^^^^^^^^^ - | - = note: this error originates in the attribute macro `sorted` (in Nightly builds, run with -Z macro-backtrace for more info) +20 | E::Bbb(_, _) => {} + | ^^^^^^ diff --git a/tests/ui/unsorted-match-unstable.stderr b/tests/ui/unsorted-match-unstable.stderr index 6ba18e8..42daef5 100644 --- a/tests/ui/unsorted-match-unstable.stderr +++ b/tests/ui/unsorted-match-unstable.stderr @@ -1,7 +1,5 @@ error: E::Bbb should sort before E::Ddd - --> tests/ui/unsorted-match-unstable.rs:15:5 + --> tests/ui/unsorted-match-unstable.rs:21:9 | -15 | #[sorted] - | ^^^^^^^^^ - | - = note: this error originates in the attribute macro `sorted` (in Nightly builds, run with -Z macro-backtrace for more info) +21 | E::Bbb(_, _) => {} + | ^^^^^^ From e0e7625df6a4684245bdf95055d64c23bde91f2d Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 24 Oct 2022 21:38:38 -0700 Subject: [PATCH 2/2] Resolve needless_pass_by_value pedantic clippy lint error: this argument is passed by value, but not consumed in the function body --> src/emit.rs:13:18 | 13 | pub fn emit(err: Error, kind: Kind, output: TokenStream) -> TokenStream { | ^^^^^ help: consider taking a reference instead: `&Error` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value = note: `-D clippy::needless-pass-by-value` implied by `-D clippy::pedantic` --- src/emit.rs | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/emit.rs b/src/emit.rs index 68a24f6..c7717aa 100644 --- a/src/emit.rs +++ b/src/emit.rs @@ -10,7 +10,7 @@ pub enum Kind { Let, } -pub fn emit(err: Error, kind: Kind, output: TokenStream) -> TokenStream { +pub fn emit(err: &Error, kind: Kind, output: TokenStream) -> TokenStream { let err = err.to_compile_error(); let output = proc_macro2::TokenStream::from(output); diff --git a/src/lib.rs b/src/lib.rs index 2204a1c..8511ab8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -183,7 +183,7 @@ pub fn sorted(args: TokenStream, input: TokenStream) -> TokenStream { match result { Ok(_) => output, - Err(err) => emit(err, kind, output), + Err(err) => emit(&err, kind, output), } }