1
Fork 0

single-use-lifetime lint: don't false-positive on the anonymous lifetime

This commit is contained in:
Zack M. Davis 2018-10-28 00:13:18 -07:00
parent fd28753e83
commit faea5bbc65
3 changed files with 13 additions and 5 deletions

View file

@ -1593,6 +1593,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
_ => None, _ => None,
} { } {
debug!("id = {:?} span = {:?} name = {:?}", node_id, span, name); debug!("id = {:?} span = {:?} name = {:?}", node_id, span, name);
if name == keywords::UnderscoreLifetime.ident() {
continue;
}
let mut err = self.tcx.struct_span_lint_node( let mut err = self.tcx.struct_span_lint_node(
lint::builtin::SINGLE_USE_LIFETIMES, lint::builtin::SINGLE_USE_LIFETIMES,
id, id,

View file

@ -12,10 +12,8 @@
#![allow(dead_code)] #![allow(dead_code)]
#![allow(unused_variables)] #![allow(unused_variables)]
// Test that we DO warn for a lifetime used only once in an impl. // Test that we DO warn for a lifetime used only once in an impl, and that we
// // don't warn for the anonymous lifetime.
// (Actually, until #15872 is fixed, you can't use `'_` here, but
// hopefully that will come soon.)
struct Foo<'f> { struct Foo<'f> {
data: &'f u32 data: &'f u32
@ -26,4 +24,9 @@ impl<'f> Foo<'f> { //~ ERROR `'f` only used once
} }
} }
impl Foo<'_> {
fn inherent_b(&self) {}
}
fn main() { } fn main() { }

View file

@ -1,5 +1,5 @@
error: lifetime parameter `'f` only used once 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 LL | impl<'f> Foo<'f> { //~ ERROR `'f` only used once
| ^^ -- ...is used only here | ^^ -- ...is used only here