`let_underscore_lock` suggestion crosses macro boundaries

Abierto
#165,650 0 comentarios 1 reacción 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

  • #165661 de @2Zest — cerrado sin fusionar

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
rust
Área
compilers

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Rust
Estrellas
121k
Forks
17.3k
Merge medio
2 d 21 h
PR fusionados (30 d)
531

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de rust-lang/rust

Todos los issues de rust-lang/rust

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.