From 89a184a39921f10782f986c9e5bcd8b92ef60818 Mon Sep 17 00:00:00 2001 From: Mark Mansi Date: Tue, 17 Sep 2019 11:57:16 -0500 Subject: [PATCH] add test for complex suggestions --- src/test/ui/nll/outlives-suggestion-more.rs | 28 +++++ .../ui/nll/outlives-suggestion-more.stderr | 100 ++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 src/test/ui/nll/outlives-suggestion-more.rs create mode 100644 src/test/ui/nll/outlives-suggestion-more.stderr diff --git a/src/test/ui/nll/outlives-suggestion-more.rs b/src/test/ui/nll/outlives-suggestion-more.rs new file mode 100644 index 00000000000..4d80b78ac65 --- /dev/null +++ b/src/test/ui/nll/outlives-suggestion-more.rs @@ -0,0 +1,28 @@ +// Test the more elaborate outlives suggestions. + +#![feature(nll)] + +// Should suggest: 'a: 'c, 'b: 'd +fn foo1<'a, 'b, 'c, 'd>(x: &'a usize, y: &'b usize) -> (&'c usize, &'d usize) { + (x, y) //~ERROR lifetime may not live long enough + //~^ERROR lifetime may not live long enough +} + +// Should suggest: 'a: 'c and use 'static instead of 'b +fn foo2<'a, 'b, 'c>(x: &'a usize, y: &'b usize) -> (&'c usize, &'static usize) { + (x, y) //~ERROR lifetime may not live long enough + //~^ERROR lifetime may not live long enough +} + +// Should suggest: 'a and 'b are the same and use 'static instead of 'c +fn foo3<'a, 'b, 'c, 'd, 'e>( + x: &'a usize, + y: &'b usize, + z: &'c usize, +) -> (&'b usize, &'a usize, &'static usize) { + (x, y, z) //~ERROR lifetime may not live long enough + //~^ERROR lifetime may not live long enough + //~^^ERROR lifetime may not live long enough +} + +fn main() {} diff --git a/src/test/ui/nll/outlives-suggestion-more.stderr b/src/test/ui/nll/outlives-suggestion-more.stderr new file mode 100644 index 00000000000..2ebcbf5cbaf --- /dev/null +++ b/src/test/ui/nll/outlives-suggestion-more.stderr @@ -0,0 +1,100 @@ +error: lifetime may not live long enough + --> $DIR/outlives-suggestion-more.rs:7:5 + | +LL | fn foo1<'a, 'b, 'c, 'd>(x: &'a usize, y: &'b usize) -> (&'c usize, &'d usize) { + | -- -- lifetime `'c` defined here + | | + | lifetime `'a` defined here +LL | (x, y) + | ^^^^^^ returning this value requires that `'a` must outlive `'c` + | + = help: consider adding the following bound: `'a: 'c` + +error: lifetime may not live long enough + --> $DIR/outlives-suggestion-more.rs:7:5 + | +LL | fn foo1<'a, 'b, 'c, 'd>(x: &'a usize, y: &'b usize) -> (&'c usize, &'d usize) { + | -- -- lifetime `'d` defined here + | | + | lifetime `'b` defined here +LL | (x, y) + | ^^^^^^ returning this value requires that `'b` must outlive `'d` + | + = help: consider adding the following bound: `'b: 'd` + +help: the following changes may resolve your lifetime errors + | + = help: add bound `'a: 'c` + = help: add bound `'b: 'd` + +error: lifetime may not live long enough + --> $DIR/outlives-suggestion-more.rs:13:5 + | +LL | fn foo2<'a, 'b, 'c>(x: &'a usize, y: &'b usize) -> (&'c usize, &'static usize) { + | -- -- lifetime `'c` defined here + | | + | lifetime `'a` defined here +LL | (x, y) + | ^^^^^^ returning this value requires that `'a` must outlive `'c` + | + = help: consider adding the following bound: `'a: 'c` + +error: lifetime may not live long enough + --> $DIR/outlives-suggestion-more.rs:13:5 + | +LL | fn foo2<'a, 'b, 'c>(x: &'a usize, y: &'b usize) -> (&'c usize, &'static usize) { + | -- lifetime `'b` defined here +LL | (x, y) + | ^^^^^^ returning this value requires that `'b` must outlive `'static` + | + = help: consider replacing `'b` with `'static` + +help: the following changes may resolve your lifetime errors + | + = help: add bound `'a: 'c` + = help: replace `'b` with `'static` + +error: lifetime may not live long enough + --> $DIR/outlives-suggestion-more.rs:23:5 + | +LL | fn foo3<'a, 'b, 'c, 'd, 'e>( + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +... +LL | (x, y, z) + | ^^^^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` + | + = help: consider adding the following bound: `'a: 'b` + +error: lifetime may not live long enough + --> $DIR/outlives-suggestion-more.rs:23:5 + | +LL | fn foo3<'a, 'b, 'c, 'd, 'e>( + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +... +LL | (x, y, z) + | ^^^^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b` + | + = help: consider adding the following bound: `'b: 'a` + +error: lifetime may not live long enough + --> $DIR/outlives-suggestion-more.rs:23:5 + | +LL | fn foo3<'a, 'b, 'c, 'd, 'e>( + | -- lifetime `'c` defined here +... +LL | (x, y, z) + | ^^^^^^^^^ returning this value requires that `'c` must outlive `'static` + | + = help: consider replacing `'c` with `'static` + +help: the following changes may resolve your lifetime errors + | + = help: `'a` and `'b` must be the same: replace one with the other + = help: replace `'c` with `'static` + +error: aborting due to 7 previous errors +