Static rustc_lint_defs::builtin::SINGLE_USE_LIFETIMES
source · pub static SINGLE_USE_LIFETIMES: &'static Lint
Expand description
The single_use_lifetimes
lint detects lifetimes that are only used
once.
Example
ⓘ
#![deny(single_use_lifetimes)]
fn foo<'a>(x: &'a u32) {}
{{produces}}
Explanation
Specifying an explicit lifetime like 'a
in a function or impl
should only be used to link together two things. Otherwise, you should
just use '_
to indicate that the lifetime is not linked to anything,
or elide the lifetime altogether if possible.
This lint is “allow” by default because it was introduced at a time
when '_
and elided lifetimes were first being introduced, and this
lint would be too noisy. Also, there are some known false positives
that it produces. See RFC 2115 for historical context, and issue
#44752 for more details.