single-use-lifetime lint: don't false-positive on the anonymous lifetime
This commit is contained in:
parent
fd28753e83
commit
faea5bbc65
3 changed files with 13 additions and 5 deletions
|
@ -1593,6 +1593,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
|||
_ => None,
|
||||
} {
|
||||
debug!("id = {:?} span = {:?} name = {:?}", node_id, span, name);
|
||||
|
||||
if name == keywords::UnderscoreLifetime.ident() {
|
||||
continue;
|
||||
}
|
||||
|
||||
let mut err = self.tcx.struct_span_lint_node(
|
||||
lint::builtin::SINGLE_USE_LIFETIMES,
|
||||
id,
|
||||
|
|
|
@ -12,10 +12,8 @@
|
|||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
|
||||
// Test that we DO warn for a lifetime used only once in an impl.
|
||||
//
|
||||
// (Actually, until #15872 is fixed, you can't use `'_` here, but
|
||||
// hopefully that will come soon.)
|
||||
// Test that we DO warn for a lifetime used only once in an impl, and that we
|
||||
// don't warn for the anonymous lifetime.
|
||||
|
||||
struct Foo<'f> {
|
||||
data: &'f u32
|
||||
|
@ -26,4 +24,9 @@ impl<'f> Foo<'f> { //~ ERROR `'f` only used once
|
|||
}
|
||||
}
|
||||
|
||||
impl Foo<'_> {
|
||||
fn inherent_b(&self) {}
|
||||
}
|
||||
|
||||
|
||||
fn main() { }
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: lifetime parameter `'f` only used once
|
||||
--> $DIR/one-use-in-inherent-impl-header.rs:24:6
|
||||
--> $DIR/one-use-in-inherent-impl-header.rs:22:6
|
||||
|
|
||||
LL | impl<'f> Foo<'f> { //~ ERROR `'f` only used once
|
||||
| ^^ -- ...is used only here
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue