]> git.lizzy.rs Git - rust.git/commitdiff
Add label to lint for lifetimes used once
authorEsteban Küber <esteban@kuber.com.ar>
Fri, 22 Jun 2018 01:17:42 +0000 (18:17 -0700)
committerEsteban Küber <esteban@kuber.com.ar>
Fri, 22 Jun 2018 01:21:49 +0000 (18:21 -0700)
src/librustc/middle/resolve_lifetime.rs
src/test/ui/single-use-lifetime/fn-types.stderr
src/test/ui/single-use-lifetime/one-use-in-fn-argument-in-band.stderr
src/test/ui/single-use-lifetime/one-use-in-fn-argument.stderr
src/test/ui/single-use-lifetime/one-use-in-inherent-impl-header.stderr
src/test/ui/single-use-lifetime/one-use-in-inherent-method-argument.stderr
src/test/ui/single-use-lifetime/one-use-in-inherent-method-return.stderr
src/test/ui/single-use-lifetime/one-use-in-trait-method-argument.stderr
src/test/ui/single-use-lifetime/two-uses-in-inherent-method-argument-and-return.stderr

index f73e0ab2a9d774bcd2ed12ad896f0dea57597ccb..025ee0f3d746cc6fc60f022715a4012ab28ada75 100644 (file)
@@ -1395,7 +1395,7 @@ fn check_uses_for_lifetimes_defined_by_scope(&mut self) {
                 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 @@ fn check_uses_for_lifetimes_defined_by_scope(&mut self) {
                         _ => 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) => {
index 6b8417bf9db6d8b131ff6479fdb787b195f20f2e..6fd2b320472f3cd5c623906ff208d2cbf995ec49 100644 (file)
@@ -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
index 3694c2452f34c0ecb810728cea63d099a5a2c4fe..3dd2675646cde0918112259118a93d20b61ee72f 100644 (file)
@@ -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
 
index f1304568fe72cb6a32b32642191eb77cd8cc3ab4..4c13133581bb4d156433031f8ce36404b257a6d1 100644 (file)
@@ -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
index 8f91ca0ce54c32a27899ea479c1725c7c614faa2..2509366f9696fb080dbe1d2b21b5740c89d51e9b 100644 (file)
@@ -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
index 4811a65ced91975849b5ffc96f30fd4cfb301f4a..cfc8dbf18dc01d02c07045acf6eeacad050a748e 100644 (file)
@@ -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
 
index b552c8475d8900800ddabc0a77f1581c6277325e..8aa19d4e3ee916e7c1e9c463ea16e9ab6b30ad56 100644 (file)
@@ -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
index de74800ff60140a2aa97b15e241d6f804dd27b0e..4a796d83242fd91570718d2a72c8e77b8ecf5bae 100644 (file)
@@ -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
index ca0b050b696793dca7c44879adc245fcf3ed885a..b4b370d6e976b81645c8b8c409da752da3579674 100644 (file)
@@ -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