Skip to content

Commit e12d682

Browse files
committed
path-type examples for single-use lifetime in fn argument UI test
Niko Matsakis commented in October 2017 (#44752 (comment)) that these should lint. They do! Let's reify that in the tests now (and then we'll see a nice diff when we add suggestions in a future commit).
1 parent dfd52ba commit e12d682

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,11 @@ fn a<'a>(x: &'a u32) { //~ ERROR `'a` only used once
99
//~^ HELP elide the single-use lifetime
1010
}
1111

12+
struct Single<'a> { x: &'a u32 }
13+
struct Double<'a, 'b> { f: &'a &'b u32 }
14+
15+
fn center<'m>(_: Single<'m>) {} //~ ERROR `'m` only used once
16+
fn left<'x, 'y>(foo: Double<'x, 'y>) -> &'x u32 { foo.f } //~ ERROR `'y` only used once
17+
fn right<'x, 'y>(foo: Double<'x, 'y>) -> &'y u32 { foo.f } //~ ERROR `'x` only used once
18+
1219
fn main() { }

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,25 @@ help: elide the single-use lifetime
1616
LL | fn a(x: &u32) {
1717
| -- --
1818

19-
error: aborting due to previous error
19+
error: lifetime parameter `'m` only used once
20+
--> $DIR/one-use-in-fn-argument.rs:15:11
21+
|
22+
LL | fn center<'m>(_: Single<'m>) {}
23+
| ^^ -- ...is used only here
24+
| |
25+
| this lifetime...
26+
27+
error: lifetime parameter `'y` only used once
28+
--> $DIR/one-use-in-fn-argument.rs:16:13
29+
|
30+
LL | fn left<'x, 'y>(foo: Double<'x, 'y>) -> &'x u32 { foo.f }
31+
| ^^ this lifetime... -- ...is used only here
32+
33+
error: lifetime parameter `'x` only used once
34+
--> $DIR/one-use-in-fn-argument.rs:17:10
35+
|
36+
LL | fn right<'x, 'y>(foo: Double<'x, 'y>) -> &'y u32 { foo.f }
37+
| ^^ this lifetime... -- ...is used only here
38+
39+
error: aborting due to 4 previous errors
2040

0 commit comments

Comments
 (0)