Skip to content

Commit

Permalink
path-type examples for single-use lifetime in fn argument UI test
Browse files Browse the repository at this point in the history
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
1 parent dfd52ba commit e12d682
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/test/ui/single-use-lifetime/one-use-in-fn-argument.rs
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
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

0 comments on commit e12d682

Please sign in to comment.