`let_underscore_lock` suggestion crosses macro boundaries

Open
#165,650 0 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

  • #165661 by @2Zest — closed without merging

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
rust
Domain
compilers

Research direction

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.

Written by the indexing model from the issue text.

Description

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

Dominant language
Rust
Stars
121k
Forks
17.3k
Avg merge
2d 21h
Merged PRs (30d)
531

Getting set up

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.

More from rust-lang/rust

All issues in rust-lang/rust

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.