-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unit_arg lint for Rocket handlers returning unit causes a warning #6514
Comments
This comment has been minimized.
This comment has been minimized.
Alright, I managed to extract a #[proc_macro_attribute]
pub fn rocket_get(_args: TokenStream, input: TokenStream) -> TokenStream {
let input_fn: syn::ItemFn = syn::parse(input).unwrap();
// This needs to be quote_spanned! with the span of the input signature otherwise the issue couldn't be reproduced
let spanned = quote_spanned! { input_fn.sig.ident.span() =>
fn unitfn(_: ()) {}
#[allow(clippy::no_effect)]
unitfn({ 1; });
};
let output = quote! {
#[allow(unused, clippy::no_effect)]
#input_fn
fn foo() {
#spanned
}
};
output.into()
} Unfortunately a simple external macro check didn't fix the issue, so I will continue working on this tomorrow =) |
Unfortunately, neither Clippy nor rustc currently have a way to tell apart a |
I don't have much experience with procedural macros. Is this something that can/should be fixed in the library? Maybe using |
Personally, I would consider that only a workaround (I don't know if There has been some more discussion on Zulip: https://rust-lang.zulipchat.com/#narrow/stream/147480-t-compiler.2Fwg-diagnostics/topic/Telling.20apart.20.60quote_spanned.60.20from.20non-macro.20.20spans.3F Essentially, we would need some extra 'this span was produced by macro expansion' state that is not modified by any of the proc_macro APIs. |
More proc-macro detection fixes #6514 fixes #8683 fixes #6858 fixes #6594 This is a more general way of checking if an expression comes from a macro and could be trivially applied to other lints. Ideally this would be fixed in rustc's proc-macro api, but I don't see that happening any time soon. changelog: Don't lint `unit_arg` when generated by a proc-macro.
Lint name:
unit_arg
I tried this code:
with the following
Cargo.toml
:I expected to see this happen: no warning
Instead, this happened:
See also rwf2/Rocket#1495.
Meta
cargo clippy -V
: clippy 0.0.212 (2987785 2020-12-28)rustc -Vv
:The text was updated successfully, but these errors were encountered: