rust
rust copied to clipboard
confusable_idents lint should cover lifetime annotations
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.
@rustbot claim