Skip to content

Commit faea5bb

Browse files
committed
single-use-lifetime lint: don't false-positive on the anonymous lifetime
1 parent fd28753 commit faea5bb

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/librustc/middle/resolve_lifetime.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
15931593
_ => None,
15941594
} {
15951595
debug!("id = {:?} span = {:?} name = {:?}", node_id, span, name);
1596+
1597+
if name == keywords::UnderscoreLifetime.ident() {
1598+
continue;
1599+
}
1600+
15961601
let mut err = self.tcx.struct_span_lint_node(
15971602
lint::builtin::SINGLE_USE_LIFETIMES,
15981603
id,

src/test/ui/single-use-lifetime/one-use-in-inherent-impl-header.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
#![allow(dead_code)]
1313
#![allow(unused_variables)]
1414

15-
// Test that we DO warn for a lifetime used only once in an impl.
16-
//
17-
// (Actually, until #15872 is fixed, you can't use `'_` here, but
18-
// hopefully that will come soon.)
15+
// Test that we DO warn for a lifetime used only once in an impl, and that we
16+
// don't warn for the anonymous lifetime.
1917

2018
struct Foo<'f> {
2119
data: &'f u32
@@ -26,4 +24,9 @@ impl<'f> Foo<'f> { //~ ERROR `'f` only used once
2624
}
2725
}
2826

27+
impl Foo<'_> {
28+
fn inherent_b(&self) {}
29+
}
30+
31+
2932
fn main() { }

src/test/ui/single-use-lifetime/one-use-in-inherent-impl-header.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: lifetime parameter `'f` only used once
2-
--> $DIR/one-use-in-inherent-impl-header.rs:24:6
2+
--> $DIR/one-use-in-inherent-impl-header.rs:22:6
33
|
44
LL | impl<'f> Foo<'f> { //~ ERROR `'f` only used once
55
| ^^ -- ...is used only here

0 commit comments

Comments
 (0)