Make explain borrow work for Universal lifetimes

This commit is contained in:
Santiago Pastorino 2018-03-01 11:56:43 -03:00
parent 834e39289d
commit ff7dca50a4
No known key found for this signature in database
GPG key ID: 88C941CDA1D46432
14 changed files with 127 additions and 22 deletions

View file

@ -0,0 +1,22 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-flags: -Znll-dump-cause
#![feature(nll)]
#![allow(warnings)]
fn foo<'a>(x: &'a (u32,)) -> &'a u32 {
let v = 22;
&v
//~^ ERROR `v` does not live long enough [E0597]
}
fn main() {}

View file

@ -0,0 +1,18 @@
error[E0597]: `v` does not live long enough
--> $DIR/borrowed-universal-error-2.rs:18:5
|
LL | &v
| ^^ borrowed value does not live long enough
LL | //~^ ERROR `v` does not live long enough [E0597]
LL | }
| - borrowed value only lives until here
|
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 16:1...
--> $DIR/borrowed-universal-error-2.rs:16:1
|
LL | fn foo<'a>(x: &'a (u32,)) -> &'a u32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
If you want more information on this error, try using "rustc --explain E0597"

View file

@ -0,0 +1,26 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-flags: -Znll-dump-cause
#![feature(nll)]
#![allow(warnings)]
fn gimme(x: &(u32,)) -> &u32 {
&x.0
}
fn foo<'a>(x: &'a (u32,)) -> &'a u32 {
let v = 22;
gimme(&(v,))
//~^ ERROR borrowed value does not live long enough [E0597]
}
fn main() {}

View file

@ -0,0 +1,18 @@
error[E0597]: borrowed value does not live long enough
--> $DIR/borrowed-universal-error.rs:22:12
|
LL | gimme(&(v,))
| ^^^^ temporary value does not live long enough
LL | //~^ ERROR borrowed value does not live long enough [E0597]
LL | }
| - temporary value only lives until here
|
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 20:1...
--> $DIR/borrowed-universal-error.rs:20:1
|
LL | fn foo<'a>(x: &'a (u32,)) -> &'a u32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
If you want more information on this error, try using "rustc --explain E0597"

View file

@ -9,8 +9,6 @@ LL | }
LL |
LL | deref(p);
| - borrow later used here
|
= note: borrowed value must be valid for lifetime '_#5r...
error: aborting due to previous error

View file

@ -34,8 +34,6 @@ LL | }
LL |
LL | deref(p);
| - borrow later used here
|
= note: borrowed value must be valid for lifetime '_#6r...
error: aborting due to previous error

View file

@ -61,8 +61,6 @@ LL | }
LL |
LL | deref(p);
| - borrow later used here
|
= note: borrowed value must be valid for lifetime '_#4r...
error: aborting due to previous error

View file

@ -38,8 +38,6 @@ LL | }
LL |
LL | deref(p);
| - borrow later used here
|
= note: borrowed value must be valid for lifetime '_#4r...
error: aborting due to previous error

View file

@ -78,8 +78,6 @@ LL | let cell = Cell::new(&a);
...
LL | }
| - borrowed value only lives until here
|
= note: borrowed value must be valid for lifetime '_#2r...
error: aborting due to 2 previous errors

View file

@ -6,8 +6,6 @@ LL | let ref mut x = 1234543; //~ ERROR borrowed value does not live long en
LL | x
LL | }
| - temporary value only lives until here
|
= note: borrowed value must be valid for lifetime '_#2r...
error: aborting due to previous error