diff options
| author | Zack M. Davis <code@zackmdavis.net> | 2019-07-06 13:20:35 -0700 |
|---|---|---|
| committer | Zack M. Davis <code@zackmdavis.net> | 2019-07-06 15:04:18 -0700 |
| commit | e12d682dde0adbbde3d49dd202b223deb1ceec89 (patch) | |
| tree | 7c61f80c824798d6929b2796fb739906ac361bdf | |
| parent | dfd52ba6ac2262c6b61c59ec86bfd23e4e53d3de (diff) | |
| download | rust-e12d682dde0adbbde3d49dd202b223deb1ceec89.tar.gz rust-e12d682dde0adbbde3d49dd202b223deb1ceec89.zip | |
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).
| -rw-r--r-- | src/test/ui/single-use-lifetime/one-use-in-fn-argument.rs | 7 | ||||
| -rw-r--r-- | src/test/ui/single-use-lifetime/one-use-in-fn-argument.stderr | 22 |
2 files changed, 28 insertions, 1 deletions
diff --git a/src/test/ui/single-use-lifetime/one-use-in-fn-argument.rs b/src/test/ui/single-use-lifetime/one-use-in-fn-argument.rs index 900e8434d4f..60435c4ad24 100644 --- a/src/test/ui/single-use-lifetime/one-use-in-fn-argument.rs +++ b/src/test/ui/single-use-lifetime/one-use-in-fn-argument.rs @@ -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() { } diff --git a/src/test/ui/single-use-lifetime/one-use-in-fn-argument.stderr b/src/test/ui/single-use-lifetime/one-use-in-fn-argument.stderr index 4bf08534b8c..e8513e6647a 100644 --- a/src/test/ui/single-use-lifetime/one-use-in-fn-argument.stderr +++ b/src/test/ui/single-use-lifetime/one-use-in-fn-argument.stderr @@ -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 |
