]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/nll/outlives-suggestion-simple.rs
1 // Test the simplest of outlives suggestions.
5 fn foo1
<'a
, 'b
>(x
: &'a
usize) -> &'b
usize {
6 x
//~ERROR lifetime may not live long enough
9 fn foo2
<'a
>(x
: &'a
usize) -> &'
static usize {
10 x
//~ERROR lifetime may not live long enough
13 fn foo3
<'a
, 'b
>(x
: &'a
usize, y
: &'b
usize) -> (&'b
usize, &'a
usize) {
14 (x
, y
) //~ERROR lifetime may not live long enough
15 //~^ERROR lifetime may not live long enough
18 fn foo4
<'a
, 'b
, 'c
>(x
: &'a
usize) -> (&'b
usize, &'c
usize) {
19 // FIXME: ideally, we suggest 'a: 'b + 'c, but as of today (may 04, 2019), the null error
20 // reporting stops after the first error in a MIR def so as not to produce too many errors, so
21 // currently we only report 'a: 'b. The user would then re-run and get another error.
22 (x
, x
) //~ERROR lifetime may not live long enough
30 pub fn foo
<'a
>(x
: &'a
usize) -> Self {
31 Foo { x }
//~ERROR lifetime may not live long enough
40 pub fn get
<'b
>(&self) -> &'b
usize {
41 self.x
//~ERROR lifetime may not live long enough
45 // source: https://stackoverflow.com/questions/41417057/why-do-i-get-a-lifetime-error-when-i-use-a-mutable-reference-in-a-struct-instead
51 fn get
<'b
>(&'b
self) -> &'a
i32 {
52 self.x
//~ERROR lifetime may not live long enough
56 // source: https://stackoverflow.com/questions/41204134/rust-lifetime-error
61 fn new(foo
: &'a Foo2
<'a
>) -> Bar2
<'a
> {
68 cell
: std
::cell
::Cell
<&'a
str>,
71 // should not produce outlives suggestions to name 'self
72 fn get_bar(&self) -> Bar2
{
73 Bar2
::new(&self) //~ERROR borrowed data escapes outside of associated function