Confusing message on inconsistent

Aperta
#166,149 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

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.

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

Descrizione

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.
Lingua principale
Rust
Stelle
122k
Fork
16.7k
Merge medio
2g 16h
PR unite (30g)
515

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.