]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/nll/outlives-suggestion-simple.rs
1 // Test the simplest of outlives suggestions.
3 fn foo1
<'a
, 'b
>(x
: &'a
usize) -> &'b
usize {
4 x
//~ERROR lifetime may not live long enough
7 fn foo2
<'a
>(x
: &'a
usize) -> &'
static usize {
8 x
//~ERROR lifetime may not live long enough
11 fn foo3
<'a
, 'b
>(x
: &'a
usize, y
: &'b
usize) -> (&'b
usize, &'a
usize) {
12 (x
, y
) //~ERROR lifetime may not live long enough
13 //~^ERROR lifetime may not live long enough
16 fn foo4
<'a
, 'b
, 'c
>(x
: &'a
usize) -> (&'b
usize, &'c
usize) {
17 // FIXME: ideally, we suggest 'a: 'b + 'c, but as of today (may 04, 2019), the null error
18 // reporting stops after the first error in a MIR def so as not to produce too many errors, so
19 // currently we only report 'a: 'b. The user would then re-run and get another error.
20 (x
, x
) //~ERROR lifetime may not live long enough
28 pub fn foo
<'a
>(x
: &'a
usize) -> Self {
29 Foo { x }
//~ERROR lifetime may not live long enough
38 pub fn get
<'b
>(&self) -> &'b
usize {
39 self.x
//~ERROR lifetime may not live long enough
43 // source: https://stackoverflow.com/questions/41417057/why-do-i-get-a-lifetime-error-when-i-use-a-mutable-reference-in-a-struct-instead
49 fn get
<'b
>(&'b
self) -> &'a
i32 {
50 self.x
//~ERROR lifetime may not live long enough
54 // source: https://stackoverflow.com/questions/41204134/rust-lifetime-error
59 fn new(foo
: &'a Foo2
<'a
>) -> Bar2
<'a
> {
66 cell
: std
::cell
::Cell
<&'a
str>,
69 // should not produce outlives suggestions to name 'self
70 fn get_bar(&self) -> Bar2
{
71 Bar2
::new(&self) //~ERROR lifetime may not live long enough