Misleading warning when a variable is "unused" (used only in unreachable code)

Abierto
#166,624 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

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

Línea de trabajo

Start with the supplied Rust playground example and compare its diagnostics on Rust 1.100.0 with the earlier behavior referenced in issues #99076 and #115394. The report identifies no compiler files or tests, so first trace how unreachable code and unused-variable warnings are emitted for this example. Done means the final join is reported as unreachable, with the unused-variable warning handled consistently.

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

Descripción

A-diagnostics A-lints A-never-type D-confusing L-false-negative L-unreachable_code L-unused_variables S-has-mcve T-compiler
Code

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=b73b5e4465ed2e20db9a89d75f267fca

  let infinite_thread = thread::spawn(|| loop {});
  let finite_thread = thread::spawn(|| {});
  
  infinite_thread.join().unwrap();
  finite_thread.join().unwrap();
Current output
> warning: unused variable: `finite_thread`

But more importantly, there is not a warning that the last line is unreachable code. I found a few similar issues (#99076, #115394) but in those it sounds like the compiler emitted both warnings, for the unused variable and the unreachable code. In this case I am seeing the unused variable warning only.

Desired output
> warning: unreachable code

either in addition to or instead of the unused variable warning.

Rationale and extra context

I got this warning when upgrading from 1.99 to 1.100 and was confused at first because it seemed quite clear that finite_thread was used.

Rust Version
1.100.0
Lenguaje dominante
Rust
Estrellas
123k
Forks
16.6k
Merge medio
2 d 17 h
PR fusionados (30 d)
532

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.