about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-06-23 00:06:54 +0000
committerbors <bors@rust-lang.org>2018-06-23 00:06:54 +0000
commitf9686334ac0c71e1f2137d44f7e471292c1251da (patch)
tree8978bd8fd74ae24c2f382ca35c4d53cf51a59bc9
parentb0e41f103873908c82b86513e4698beae99d3576 (diff)
parent973baaa5b2f91876e1304272fffdea2d0679554f (diff)
downloadrust-f9686334ac0c71e1f2137d44f7e471292c1251da.tar.gz
rust-f9686334ac0c71e1f2137d44f7e471292c1251da.zip
Auto merge of #51697 - estebank:once-used-lifetime-label, r=oli-obk
Add label to lint for lifetimes used once

```
error: lifetime parameter `'a` only used once
  --> $DIR/fn-types.rs:19:10
   |
LL |   a: for<'a> fn(&'a u32), //~ ERROR `'a` only used once
   |          ^^      -- ...is used only here
   |          |
   |          this lifetime...
```
-rw-r--r--src/librustc/middle/resolve_lifetime.rs9
-rw-r--r--src/test/ui/single-use-lifetime/fn-types.stderr4
-rw-r--r--src/test/ui/single-use-lifetime/one-use-in-fn-argument-in-band.stderr6
-rw-r--r--src/test/ui/single-use-lifetime/one-use-in-fn-argument.stderr4
-rw-r--r--src/test/ui/single-use-lifetime/one-use-in-inherent-impl-header.stderr4
-rw-r--r--src/test/ui/single-use-lifetime/one-use-in-inherent-method-argument.stderr8
-rw-r--r--src/test/ui/single-use-lifetime/one-use-in-inherent-method-return.stderr4
-rw-r--r--src/test/ui/single-use-lifetime/one-use-in-trait-method-argument.stderr4
-rw-r--r--src/test/ui/single-use-lifetime/two-uses-in-inherent-method-argument-and-return.stderr4
9 files changed, 36 insertions, 11 deletions
diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs
index f73e0ab2a9d..025ee0f3d74 100644
--- a/src/librustc/middle/resolve_lifetime.rs
+++ b/src/librustc/middle/resolve_lifetime.rs
@@ -1395,7 +1395,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
                 lifetimeuseset
             );
             match lifetimeuseset {
-                Some(LifetimeUseSet::One(_)) => {
+                Some(LifetimeUseSet::One(lifetime)) => {
                     let node_id = self.tcx.hir.as_local_node_id(def_id).unwrap();
                     debug!("node id first={:?}", node_id);
                     if let Some((id, span, name)) = match self.tcx.hir.get(node_id) {
@@ -1408,12 +1408,15 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
                         _ => None,
                     } {
                         debug!("id = {:?} span = {:?} name = {:?}", node_id, span, name);
-                        self.tcx.struct_span_lint_node(
+                        let mut err = self.tcx.struct_span_lint_node(
                             lint::builtin::SINGLE_USE_LIFETIMES,
                             id,
                             span,
                             &format!("lifetime parameter `{}` only used once", name),
-                        ).emit();
+                        );
+                        err.span_label(span, "this lifetime...");
+                        err.span_label(lifetime.span, "...is used only here");
+                        err.emit();
                     }
                 }
                 Some(LifetimeUseSet::Many) => {
diff --git a/src/test/ui/single-use-lifetime/fn-types.stderr b/src/test/ui/single-use-lifetime/fn-types.stderr
index 6b8417bf9db..6fd2b320472 100644
--- a/src/test/ui/single-use-lifetime/fn-types.stderr
+++ b/src/test/ui/single-use-lifetime/fn-types.stderr
@@ -2,7 +2,9 @@ error: lifetime parameter `'a` only used once
   --> $DIR/fn-types.rs:19:10
    |
 LL |   a: for<'a> fn(&'a u32), //~ ERROR `'a` only used once
-   |          ^^
+   |          ^^      -- ...is used only here
+   |          |
+   |          this lifetime...
    |
 note: lint level defined here
   --> $DIR/fn-types.rs:11:9
diff --git a/src/test/ui/single-use-lifetime/one-use-in-fn-argument-in-band.stderr b/src/test/ui/single-use-lifetime/one-use-in-fn-argument-in-band.stderr
index 3694c2452f3..3dd2675646c 100644
--- a/src/test/ui/single-use-lifetime/one-use-in-fn-argument-in-band.stderr
+++ b/src/test/ui/single-use-lifetime/one-use-in-fn-argument-in-band.stderr
@@ -3,6 +3,9 @@ error: lifetime parameter `'b` only used once
    |
 LL | fn a(x: &'a u32, y: &'b u32) {
    |                      ^^
+   |                      |
+   |                      this lifetime...
+   |                      ...is used only here
    |
 note: lint level defined here
   --> $DIR/one-use-in-fn-argument-in-band.rs:12:9
@@ -15,6 +18,9 @@ error: lifetime parameter `'a` only used once
    |
 LL | fn a(x: &'a u32, y: &'b u32) {
    |          ^^
+   |          |
+   |          this lifetime...
+   |          ...is used only here
 
 error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/single-use-lifetime/one-use-in-fn-argument.stderr b/src/test/ui/single-use-lifetime/one-use-in-fn-argument.stderr
index f1304568fe7..4c13133581b 100644
--- a/src/test/ui/single-use-lifetime/one-use-in-fn-argument.stderr
+++ b/src/test/ui/single-use-lifetime/one-use-in-fn-argument.stderr
@@ -2,7 +2,9 @@ error: lifetime parameter `'a` only used once
   --> $DIR/one-use-in-fn-argument.rs:18:6
    |
 LL | fn a<'a>(x: &'a u32) { //~ ERROR `'a` only used once
-   |      ^^
+   |      ^^      -- ...is used only here
+   |      |
+   |      this lifetime...
    |
 note: lint level defined here
   --> $DIR/one-use-in-fn-argument.rs:11:9
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 8f91ca0ce54..2509366f969 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
@@ -2,7 +2,9 @@ error: lifetime parameter `'f` only used once
   --> $DIR/one-use-in-inherent-impl-header.rs:24:6
    |
 LL | impl<'f> Foo<'f> { //~ ERROR `'f` only used once
-   |      ^^
+   |      ^^      -- ...is used only here
+   |      |
+   |      this lifetime...
    |
 note: lint level defined here
   --> $DIR/one-use-in-inherent-impl-header.rs:11:9
diff --git a/src/test/ui/single-use-lifetime/one-use-in-inherent-method-argument.stderr b/src/test/ui/single-use-lifetime/one-use-in-inherent-method-argument.stderr
index 4811a65ced9..cfc8dbf18dc 100644
--- a/src/test/ui/single-use-lifetime/one-use-in-inherent-method-argument.stderr
+++ b/src/test/ui/single-use-lifetime/one-use-in-inherent-method-argument.stderr
@@ -2,7 +2,9 @@ error: lifetime parameter `'a` only used once
   --> $DIR/one-use-in-inherent-method-argument.rs:22:19
    |
 LL |     fn inherent_a<'a>(&self, data: &'a u32) { //~ ERROR `'a` only used once
-   |                   ^^
+   |                   ^^                -- ...is used only here
+   |                   |
+   |                   this lifetime...
    |
 note: lint level defined here
   --> $DIR/one-use-in-inherent-method-argument.rs:11:9
@@ -14,7 +16,9 @@ error: lifetime parameter `'f` only used once
   --> $DIR/one-use-in-inherent-method-argument.rs:21:6
    |
 LL | impl<'f> Foo<'f> { //~ ERROR `'f` only used once
-   |      ^^
+   |      ^^      -- ...is used only here
+   |      |
+   |      this lifetime...
 
 error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/single-use-lifetime/one-use-in-inherent-method-return.stderr b/src/test/ui/single-use-lifetime/one-use-in-inherent-method-return.stderr
index b552c8475d8..8aa19d4e3ee 100644
--- a/src/test/ui/single-use-lifetime/one-use-in-inherent-method-return.stderr
+++ b/src/test/ui/single-use-lifetime/one-use-in-inherent-method-return.stderr
@@ -2,7 +2,9 @@ error: lifetime parameter `'f` only used once
   --> $DIR/one-use-in-inherent-method-return.rs:22:6
    |
 LL | impl<'f> Foo<'f> { //~ ERROR `'f` only used once
-   |      ^^
+   |      ^^      -- ...is used only here
+   |      |
+   |      this lifetime...
    |
 note: lint level defined here
   --> $DIR/one-use-in-inherent-method-return.rs:11:9
diff --git a/src/test/ui/single-use-lifetime/one-use-in-trait-method-argument.stderr b/src/test/ui/single-use-lifetime/one-use-in-trait-method-argument.stderr
index de74800ff60..4a796d83242 100644
--- a/src/test/ui/single-use-lifetime/one-use-in-trait-method-argument.stderr
+++ b/src/test/ui/single-use-lifetime/one-use-in-trait-method-argument.stderr
@@ -2,7 +2,9 @@ error: lifetime parameter `'g` only used once
   --> $DIR/one-use-in-trait-method-argument.rs:25:13
    |
 LL |     fn next<'g>(&'g mut self) -> Option<Self::Item> { //~ ERROR `'g` only used once
-   |             ^^
+   |             ^^   -- ...is used only here
+   |             |
+   |             this lifetime...
    |
 note: lint level defined here
   --> $DIR/one-use-in-trait-method-argument.rs:14:9
diff --git a/src/test/ui/single-use-lifetime/two-uses-in-inherent-method-argument-and-return.stderr b/src/test/ui/single-use-lifetime/two-uses-in-inherent-method-argument-and-return.stderr
index ca0b050b696..b4b370d6e97 100644
--- a/src/test/ui/single-use-lifetime/two-uses-in-inherent-method-argument-and-return.stderr
+++ b/src/test/ui/single-use-lifetime/two-uses-in-inherent-method-argument-and-return.stderr
@@ -2,7 +2,9 @@ error: lifetime parameter `'f` only used once
   --> $DIR/two-uses-in-inherent-method-argument-and-return.rs:22:6
    |
 LL | impl<'f> Foo<'f> { //~ ERROR `'f` only used once
-   |      ^^
+   |      ^^      -- ...is used only here
+   |      |
+   |      this lifetime...
    |
 note: lint level defined here
   --> $DIR/two-uses-in-inherent-method-argument-and-return.rs:14:9