rust-lang / rust-lang/rust-clippy

Lint against `quote::quote!`

Open
#12,397 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.