about summary refs log tree commit diff
diff options
context:
space:
mode:
authorZack M. Davis <code@zackmdavis.net>2018-10-28 00:13:18 -0700
committerZack M. Davis <code@zackmdavis.net>2018-10-28 00:14:41 -0700
commitfaea5bbc650d93e28e4a89a62aee0dc1409b08c7 (patch)
tree32c36dcaec10cc43f9bc7bc4f6c21cbd52f7f200
parentfd28753e83ac0599357aef8df4b25996e7f4a630 (diff)
downloadrust-faea5bbc650d93e28e4a89a62aee0dc1409b08c7.tar.gz
rust-faea5bbc650d93e28e4a89a62aee0dc1409b08c7.zip
single-use-lifetime lint: don't false-positive on the anonymous lifetime
-rw-r--r--src/librustc/middle/resolve_lifetime.rs5
-rw-r--r--src/test/ui/single-use-lifetime/one-use-in-inherent-impl-header.rs11
-rw-r--r--src/test/ui/single-use-lifetime/one-use-in-inherent-impl-header.stderr2
3 files changed, 13 insertions, 5 deletions
diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs
index 67a564299b0..31e34895052 100644
--- a/src/librustc/middle/resolve_lifetime.rs
+++ b/src/librustc/middle/resolve_lifetime.rs
@@ -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,
diff --git a/src/test/ui/single-use-lifetime/one-use-in-inherent-impl-header.rs b/src/test/ui/single-use-lifetime/one-use-in-inherent-impl-header.rs
index a862bbbe30c..b392f7a5174 100644
--- a/src/test/ui/single-use-lifetime/one-use-in-inherent-impl-header.rs
+++ b/src/test/ui/single-use-lifetime/one-use-in-inherent-impl-header.rs
@@ -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() { }
diff --git a/src/test/ui/single-use-lifetime/one-use-in-inherent-impl-header.stderr b/src/test/ui/single-use-lifetime/one-use-in-inherent-impl-header.stderr
index 2509366f969..40dfa677d0a 100644
--- a/src/test/ui/single-use-lifetime/one-use-in-inherent-impl-header.stderr
+++ b/src/test/ui/single-use-lifetime/one-use-in-inherent-impl-header.stderr
@@ -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