`let_underscore_lock` suggestion crosses macro boundaries

Aperta
#165,650 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #165661 di @2Zest — chiusa senza merge

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
rust
Ambito
compilers

Direzione di ricerca

Start by tracing the let_underscore_lock lint’s diagnostic and suggestion code, then inspect compiler UI tests for suggestions involving macro expansions. Reproduce the issue with the provided dbg!(m.lock().unwrap()) example and add a regression test showing the suggestion stays at the call site. Done means the output suggests drop(dbg!(m.lock().unwrap())); without pointing into the standard library macro.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

A-diagnostics D-invalid-suggestion T-compiler
Code
pub fn f(m: std::sync::Mutex<String>) {
    let _ = dbg!(m.lock().unwrap());
}
Current output
error: non-binding let on a synchronization lock
   --> src/lib.rs:2:9
    |
  2 |     let _ = dbg!(m.lock().unwrap());
    |         ^ this lock is not assigned to a binding and is immediately dropped
    |
    = note: `#[deny(let_underscore_lock)]` (part of `#[deny(let_underscore)]`) on by default
help: consider binding to an unused variable to avoid immediately dropping the value
    |
  2 |     let _unused = dbg!(m.lock().unwrap());
    |          ++++++
help: consider immediately dropping the value
   --> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/macros.rs:369:9
    |
369 -         match $val {
370 -             tmp => {
371 -                 $crate::eprintln!("[{}:{}:{}] {} = {:#?}",
372 -                     $crate::file!(),
373 -                     $crate::line!(),
374 -                     $crate::column!(),
375 -                     $crate::stringify!($val),
376 -                     // The `&T: Debug` check happens here (not in the format literal desugaring)
377 -                     // to avoid format literal related messages and suggestions.
378 -                     &&tmp as &dyn $crate::fmt::Debug,
379 -                 );
380 -                 tmp
381 -             }
382 -         }
369 +         drop()
Desired output
drop(dbg!(m.lock().unwrap()));
Rationale and extra context

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=46ca2400b4c118a940d338b6df3c9702

Other cases

Rust Version
Build using the Nightly version: 1.102.0-nightly

(2026-11-07 f5cedb83a788ea958109)
Anything else?

No response

Lingua principale
Rust
Stelle
121k
Fork
17.3k
Merge medio
2g 21h
PR unite (30g)
531

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-lang/rust

Tutte le issue di rust-lang/rust

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.