Skip to content

Add label to lint for lifetimes used once #51697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) => {
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/single-use-lifetime/fn-types.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down