Skip to content

Commit f968633

Browse files
committed
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... ```
2 parents b0e41f1 + 973baaa commit f968633

9 files changed

+36
-11
lines changed

src/librustc/middle/resolve_lifetime.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
13951395
lifetimeuseset
13961396
);
13971397
match lifetimeuseset {
1398-
Some(LifetimeUseSet::One(_)) => {
1398+
Some(LifetimeUseSet::One(lifetime)) => {
13991399
let node_id = self.tcx.hir.as_local_node_id(def_id).unwrap();
14001400
debug!("node id first={:?}", node_id);
14011401
if let Some((id, span, name)) = match self.tcx.hir.get(node_id) {
@@ -1408,12 +1408,15 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
14081408
_ => None,
14091409
} {
14101410
debug!("id = {:?} span = {:?} name = {:?}", node_id, span, name);
1411-
self.tcx.struct_span_lint_node(
1411+
let mut err = self.tcx.struct_span_lint_node(
14121412
lint::builtin::SINGLE_USE_LIFETIMES,
14131413
id,
14141414
span,
14151415
&format!("lifetime parameter `{}` only used once", name),
1416-
).emit();
1416+
);
1417+
err.span_label(span, "this lifetime...");
1418+
err.span_label(lifetime.span, "...is used only here");
1419+
err.emit();
14171420
}
14181421
}
14191422
Some(LifetimeUseSet::Many) => {

src/test/ui/single-use-lifetime/fn-types.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error: lifetime parameter `'a` only used once
22
--> $DIR/fn-types.rs:19:10
33
|
44
LL | a: for<'a> fn(&'a u32), //~ ERROR `'a` only used once
5-
| ^^
5+
| ^^ -- ...is used only here
6+
| |
7+
| this lifetime...
68
|
79
note: lint level defined here
810
--> $DIR/fn-types.rs:11:9

src/test/ui/single-use-lifetime/one-use-in-fn-argument-in-band.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ error: lifetime parameter `'b` only used once
33
|
44
LL | fn a(x: &'a u32, y: &'b u32) {
55
| ^^
6+
| |
7+
| this lifetime...
8+
| ...is used only here
69
|
710
note: lint level defined here
811
--> $DIR/one-use-in-fn-argument-in-band.rs:12:9
@@ -15,6 +18,9 @@ error: lifetime parameter `'a` only used once
1518
|
1619
LL | fn a(x: &'a u32, y: &'b u32) {
1720
| ^^
21+
| |
22+
| this lifetime...
23+
| ...is used only here
1824

1925
error: aborting due to 2 previous errors
2026

src/test/ui/single-use-lifetime/one-use-in-fn-argument.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error: lifetime parameter `'a` only used once
22
--> $DIR/one-use-in-fn-argument.rs:18:6
33
|
44
LL | fn a<'a>(x: &'a u32) { //~ ERROR `'a` only used once
5-
| ^^
5+
| ^^ -- ...is used only here
6+
| |
7+
| this lifetime...
68
|
79
note: lint level defined here
810
--> $DIR/one-use-in-fn-argument.rs:11:9

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

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

src/test/ui/single-use-lifetime/one-use-in-inherent-method-argument.stderr

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error: lifetime parameter `'a` only used once
22
--> $DIR/one-use-in-inherent-method-argument.rs:22:19
33
|
44
LL | fn inherent_a<'a>(&self, data: &'a u32) { //~ ERROR `'a` only used once
5-
| ^^
5+
| ^^ -- ...is used only here
6+
| |
7+
| this lifetime...
68
|
79
note: lint level defined here
810
--> $DIR/one-use-in-inherent-method-argument.rs:11:9
@@ -14,7 +16,9 @@ error: lifetime parameter `'f` only used once
1416
--> $DIR/one-use-in-inherent-method-argument.rs:21:6
1517
|
1618
LL | impl<'f> Foo<'f> { //~ ERROR `'f` only used once
17-
| ^^
19+
| ^^ -- ...is used only here
20+
| |
21+
| this lifetime...
1822

1923
error: aborting due to 2 previous errors
2024

src/test/ui/single-use-lifetime/one-use-in-inherent-method-return.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error: lifetime parameter `'f` only used once
22
--> $DIR/one-use-in-inherent-method-return.rs:22:6
33
|
44
LL | impl<'f> Foo<'f> { //~ ERROR `'f` only used once
5-
| ^^
5+
| ^^ -- ...is used only here
6+
| |
7+
| this lifetime...
68
|
79
note: lint level defined here
810
--> $DIR/one-use-in-inherent-method-return.rs:11:9

src/test/ui/single-use-lifetime/one-use-in-trait-method-argument.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error: lifetime parameter `'g` only used once
22
--> $DIR/one-use-in-trait-method-argument.rs:25:13
33
|
44
LL | fn next<'g>(&'g mut self) -> Option<Self::Item> { //~ ERROR `'g` only used once
5-
| ^^
5+
| ^^ -- ...is used only here
6+
| |
7+
| this lifetime...
68
|
79
note: lint level defined here
810
--> $DIR/one-use-in-trait-method-argument.rs:14:9

src/test/ui/single-use-lifetime/two-uses-in-inherent-method-argument-and-return.stderr

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error: lifetime parameter `'f` only used once
22
--> $DIR/two-uses-in-inherent-method-argument-and-return.rs:22:6
33
|
44
LL | impl<'f> Foo<'f> { //~ ERROR `'f` only used once
5-
| ^^
5+
| ^^ -- ...is used only here
6+
| |
7+
| this lifetime...
68
|
79
note: lint level defined here
810
--> $DIR/two-uses-in-inherent-method-argument-and-return.rs:14:9

0 commit comments

Comments
 (0)