Confusing message on inconsistent

Abierto
#166,149 0 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
45/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
rust
Área
compilers

Línea de trabajo

Start by tracing how the mismatched_lifetime_syntaxes lint builds its spans and help text for elided input lifetimes and hidden output lifetimes. Reproduce the example with the stated Rust version, then inspect existing lint tests for similar cases. Done means the diagnostic explains this case accurately, with tests covering the chosen wording or behavior.

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

Descripción

A-diagnostics T-compiler
Code
#![allow(dead_code)]

struct HintRef<'a>(&'a u8);

fn hint(value: &u8) -> HintRef {
    HintRef(value)
}

fn main() {}
Current output
warning: hiding a lifetime that's elided elsewhere is confusing
 --> src/main.rs:5:16
  |
5 | fn hint(value: &u8) -> HintRef {
  |                ^^^     ^^^^^^^ the same lifetime is hidden here
  |                |
  |                the lifetime is elided here
  |
  = help: the same lifetime is referred to in inconsistent ways, making the signature confusing
  = note: `#[warn(mismatched_lifetime_syntaxes)]` on by default
help: use `'_` for type paths
  |
5 | fn hint(value: &u8) -> HintRef<'_> {
  |                               ++++
Rationale and extra context

"the same lifetime is referred to in inconsistent ways" doesn't make sense in this context: neither the & nor the HintRef have any lifetime written, so arguably they are consistent?

I'm not sure what the cleanest option is here:

(1) Explicit mention of sugar:

5 | fn hint(value: &u8) -> HintRef {
  |                ^^^     ^^^^^^^ the same lifetime is hidden here
  |                |
  |                this lifetime is `_

(2) Just drop the warning in this case?

I'd also be tempted to change the span to only apply to the &, something like this:

5 | fn hint(value: &u8) -> HintRef {
  |                ^       ^^^^^^^ the same lifetime is hidden here
  |                |
  |                the lifetime is elided here
Rust Version
rustc 1.100.0 on the playground reproduces this.
Lenguaje dominante
Rust
Estrellas
122k
Forks
16.7k
Merge medio
2 d 16 h
PR fusionados (30 d)
515

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.