mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-03 12:13:43 +00:00
path-type examples for single-use lifetime in fn argument UI test
Niko Matsakis commented in October 2017 (https://github.com/rust-lang/rust/issues/44752#issuecomment-340885834) 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).
This commit is contained in:
parent
dfd52ba6ac
commit
e12d682dde
@ -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() { }
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user