rust-lang / rust-lang/rust-clippy

Cargo clippy report warnings from macros when using quote_spanned

Open
#13,264 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

Cargo clippy captures warnings from inside macros when using quote_spanned!. Attempting --fix results in: warning: failed to automatically apply fixes suggested by rustc to crate ..... after fixes were automatically applied the compiler reported errors within these files ....

Replacing quote_spanned with quote here made the bug disappear.

Reproducer

The code does not fit in a snippet, unfortunately multiple crates are required But a small reproducer may be found here

I expected to see no warnings when running cargo clippy.

Instead, this happened:

warning: this let-binding has unit value
  --> marshalable/src/lib.rs:15:5
   |
15 |     _b: (),
   |     ^^ help: omit the `let` binding: `_b;`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value
   = note: `#[warn(clippy::let_unit_value)]` on by default
warning: `marshalable` (lib) generated 1 warning (run `cargo clippy --fix --lib -p marshalable` to apply 1 suggestion)

Futhermore attempting ``--fix` causes clippy error:

warning: failed to automatically apply fixes suggested by rustc to crate `marshalable`

after fixes were automatically applied the compiler reported errors within these files:

  * marshalable/src/lib.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust-clippy/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

But this might be a side effect.

Version
rustc 1.80.1 (3f5fd8dd4 2024-08-06)
binary: rustc
commit-hash: 3f5fd8dd41153bc5fdca9427e9e05be2c767ba23
commit-date: 2024-08-06
host: x86_64-unknown-linux-gnu
release: 1.80.1
LLVM version: 18.1.7
Additional Labels

No response

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 with the reproducer linked in the issue, especially marshalable-derive/src/lib.rs at the quote_spanned! call and marshalable/src/lib.rs where the warning appears. Run cargo clippy and cargo clippy --fix on the reproducer, then compare behavior with quote; done means the macro-generated warning and failed fix are resolved without introducing compiler errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, devtools
Issue type
Bug
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.