Fully stabilize NLL
This commit is contained in:
parent
7e9b92cb43
commit
410dcc9674
985 changed files with 1824 additions and 12137 deletions
|
@ -1,8 +1,10 @@
|
|||
#### Note: this error code is no longer emitted by the compiler.
|
||||
|
||||
Reference's lifetime of borrowed content doesn't match the expected lifetime.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0312
|
||||
```compile_fail
|
||||
pub fn opt_str<'a>(maybestr: &'a Option<String>) -> &'static str {
|
||||
if maybestr.is_none() {
|
||||
"(none)"
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#### Note: this error code is no longer emitted by the compiler.
|
||||
|
||||
The type does not fulfill the required lifetime.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0477
|
||||
```compile_fail
|
||||
use std::sync::Mutex;
|
||||
|
||||
struct MyString<'a> {
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#### Note: this error code is no longer emitted by the compiler.
|
||||
|
||||
A lifetime cannot be determined in the given situation.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0495
|
||||
```compile_fail
|
||||
fn transmute_lifetime<'a, 'b, T>(t: &'a (T,)) -> &'b T {
|
||||
match (&t,) { // error!
|
||||
((u,),) => u,
|
||||
|
|
|
@ -3,39 +3,70 @@ A lifetime didn't match what was expected.
|
|||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0623
|
||||
struct Foo<'a> {
|
||||
x: &'a isize,
|
||||
}
|
||||
struct Foo<'a, 'b, T>(std::marker::PhantomData<(&'a (), &'b (), T)>)
|
||||
where
|
||||
T: Convert<'a, 'b>;
|
||||
|
||||
fn bar<'short, 'long>(c: Foo<'short>, l: &'long isize) {
|
||||
let _: Foo<'long> = c; // error!
|
||||
trait Convert<'a, 'b>: Sized {
|
||||
fn cast(&'a self) -> &'b Self;
|
||||
}
|
||||
impl<'long: 'short, 'short, T> Convert<'long, 'short> for T {
|
||||
fn cast(&'long self) -> &'short T {
|
||||
self
|
||||
}
|
||||
}
|
||||
// error
|
||||
fn badboi<'in_, 'out, T>(
|
||||
x: Foo<'in_, 'out, T>,
|
||||
sadness: &'in_ T
|
||||
) -> &'out T {
|
||||
sadness.cast()
|
||||
}
|
||||
```
|
||||
|
||||
In this example, we tried to set a value with an incompatible lifetime to
|
||||
another one (`'long` is unrelated to `'short`). We can solve this issue in
|
||||
another one (`'in_` is unrelated to `'out`). We can solve this issue in
|
||||
two different ways:
|
||||
|
||||
Either we make `'short` live at least as long as `'long`:
|
||||
Either we make `'in_` live at least as long as `'out`:
|
||||
|
||||
```
|
||||
struct Foo<'a> {
|
||||
x: &'a isize,
|
||||
}
|
||||
struct Foo<'a, 'b, T>(std::marker::PhantomData<(&'a (), &'b (), T)>)
|
||||
where
|
||||
T: Convert<'a, 'b>;
|
||||
|
||||
// we set 'short to live at least as long as 'long
|
||||
fn bar<'short: 'long, 'long>(c: Foo<'short>, l: &'long isize) {
|
||||
let _: Foo<'long> = c; // ok!
|
||||
trait Convert<'a, 'b>: Sized {
|
||||
fn cast(&'a self) -> &'b Self;
|
||||
}
|
||||
impl<'long: 'short, 'short, T> Convert<'long, 'short> for T {
|
||||
fn cast(&'long self) -> &'short T {
|
||||
self
|
||||
}
|
||||
}
|
||||
fn badboi<'in_: 'out, 'out, T>(
|
||||
x: Foo<'in_, 'out, T>,
|
||||
sadness: &'in_ T
|
||||
) -> &'out T {
|
||||
sadness.cast()
|
||||
}
|
||||
```
|
||||
|
||||
Or we use only one lifetime:
|
||||
|
||||
```
|
||||
struct Foo<'a> {
|
||||
x: &'a isize,
|
||||
struct Foo<'a, 'b, T>(std::marker::PhantomData<(&'a (), &'b (), T)>)
|
||||
where
|
||||
T: Convert<'a, 'b>;
|
||||
|
||||
trait Convert<'a, 'b>: Sized {
|
||||
fn cast(&'a self) -> &'b Self;
|
||||
}
|
||||
fn bar<'short>(c: Foo<'short>, l: &'short isize) {
|
||||
let _: Foo<'short> = c; // ok!
|
||||
impl<'long: 'short, 'short, T> Convert<'long, 'short> for T {
|
||||
fn cast(&'long self) -> &'short T {
|
||||
self
|
||||
}
|
||||
}
|
||||
fn badboi<'out, T>(x: Foo<'out, 'out, T>, sadness: &'out T) -> &'out T {
|
||||
sadness.cast()
|
||||
}
|
||||
```
|
||||
|
|
|
@ -4,8 +4,6 @@ lifetime of a type that implements the `Drop` trait.
|
|||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0713
|
||||
#![feature(nll)]
|
||||
|
||||
pub struct S<'a> { data: &'a mut String }
|
||||
|
||||
impl<'a> Drop for S<'a> {
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
#### Note: this error code is no longer emitted by the compiler.
|
||||
|
||||
Return type involving a trait did not require `'static` lifetime.
|
||||
|
||||
Erroneous code examples:
|
||||
|
||||
```compile_fail,E0759
|
||||
```compile_fail
|
||||
use std::fmt::Debug;
|
||||
|
||||
fn foo(x: &i32) -> impl Debug { // error!
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#### Note: this error code is no longer emitted by the compiler.
|
||||
|
||||
A trait object has some specific lifetime `'1`, but it was used in a way that
|
||||
requires it to have a `'static` lifetime.
|
||||
|
||||
Example of erroneous code:
|
||||
|
||||
```compile_fail,E0772
|
||||
```compile_fail
|
||||
trait BooleanLike {}
|
||||
trait Person {}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue