Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
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).
  • Loading branch information
zackmdavis committed Jul 6, 2019
commit e12d682dde0adbbde3d49dd202b223deb1ceec89
7 changes: 7 additions & 0 deletions src/test/ui/single-use-lifetime/one-use-in-fn-argument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ fn a<'a>(x: &'a u32) { //~ ERROR `'a` only used once
//~^ HELP elide the single-use lifetime
}

struct Single<'a> { x: &'a u32 }
struct Double<'a, 'b> { f: &'a &'b u32 }

fn center<'m>(_: Single<'m>) {} //~ ERROR `'m` only used once
fn left<'x, 'y>(foo: Double<'x, 'y>) -> &'x u32 { foo.f } //~ ERROR `'y` only used once
fn right<'x, 'y>(foo: Double<'x, 'y>) -> &'y u32 { foo.f } //~ ERROR `'x` only used once

fn main() { }
22 changes: 21 additions & 1 deletion src/test/ui/single-use-lifetime/one-use-in-fn-argument.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,25 @@ help: elide the single-use lifetime
LL | fn a(x: &u32) {
| -- --

error: aborting due to previous error
error: lifetime parameter `'m` only used once
--> $DIR/one-use-in-fn-argument.rs:15:11
|
LL | fn center<'m>(_: Single<'m>) {}
| ^^ -- ...is used only here
| |
| this lifetime...

error: lifetime parameter `'y` only used once
--> $DIR/one-use-in-fn-argument.rs:16:13
|
LL | fn left<'x, 'y>(foo: Double<'x, 'y>) -> &'x u32 { foo.f }
| ^^ this lifetime... -- ...is used only here

error: lifetime parameter `'x` only used once
--> $DIR/one-use-in-fn-argument.rs:17:10
|
LL | fn right<'x, 'y>(foo: Double<'x, 'y>) -> &'y u32 { foo.f }
| ^^ this lifetime... -- ...is used only here

error: aborting due to 4 previous errors