rust-lang / rust-lang/rust-clippy
Lint against `quote::quote!`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Lints against quote::quote! and recommends quote::quote_spanned!
Advantage
Proc macros have essentially zero diagnostics unless they provide such themselves, and tracking Spans, feeding them forward, is a bare-minimum requirement for this. There is a massive number of crates in the ecosystem which use quote but have absolutely execrable diagnostics because they don't bother. Because quote! is easy to use but doesn't ask for a span, they probably don't even realize they need to do this. Proc macros are somewhat of a "dark art" of Rust and people often regard them as unapproachable, and this is probably part of why.
Drawbacks
In some cases, there is genuinely no useful span, so you would just be calling Span::call_site() and feeding it in to satisfy the lint. Oh well.
Example
quote! {
pub extern "C" fn #new_wrapper_fn(#(#args)) -> #ret_ty {
#wrapped_fn(#(#args_idents))
}
}
Could be written as:
quote_spanned! { wrapped_fn_span =>
pub extern "C" fn #new_wrapper_fn(#(#args)) -> #ret_ty {
#wrapped_fn(#(#args_idents))
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing how Clippy implements lints for macro usage and how it tests suggested replacements. Use the issue's quote::quote! and quote::quote_spanned! examples to define the target pattern and expected recommendation. Done means the lint detects applicable quote! invocations, provides the suggested span-aware form, and covers cases where no useful span exists.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100