rust icon indicating copy to clipboard operation
rust copied to clipboard

confusable_idents lint should cover lifetime annotations

Open kmdreko opened this issue 4 years ago • 1 comments

Confusable identifiers for variables and types elicits a warning from the compiler:

pub fn types<p, ρ>(_: p) -> ρ { unimplemented!() }
warning: identifier pair considered confusable between `p` and `ρ`
 --> src/lib.rs:1:17
  |
1 | pub fn types<p, ρ>(_: p) -> ρ { unimplemented!() }
  |              -  ^
  |              |
  |              this is where the previous identifier occurred
  |
  = note: `#[warn(confusable_idents)]` on by default

But do not for lifetime parameters:

pub fn lifetimes<'p, 'ρ, T>(_: &'p T) -> &'ρ T { unimplemented!() }

Ideally, the compiler would emit a similar warning here.

Additionally, the case where a type or variable identifier starts with an apostrophe confusable (i.e. ʻa) should similarly clash with the typical lifetime parameter (i.e. 'a). Originally sourced from this Reddit post: An evil type signature.

kmdreko avatar Sep 04 '21 16:09 kmdreko

@rustbot claim

TaKO8Ki avatar Sep 22 '21 13:09 TaKO8Ki