diff options
| author | Jack Huey <31162821+jackh726@users.noreply.github.com> | 2022-04-01 13:13:25 -0400 |
|---|---|---|
| committer | Jack Huey <31162821+jackh726@users.noreply.github.com> | 2022-06-03 17:16:41 -0400 |
| commit | 410dcc96741716bf1b4dc9b3bf33f408f220384d (patch) | |
| tree | 7c0b73e8a30be7529a8c9ce4e63a76adfa9327a1 /compiler/rustc_error_codes | |
| parent | 7e9b92cb43a489b34e2bcb8d21f36198e02eedbc (diff) | |
| download | rust-410dcc96741716bf1b4dc9b3bf33f408f220384d.tar.gz rust-410dcc96741716bf1b4dc9b3bf33f408f220384d.zip | |
Fully stabilize NLL
Diffstat (limited to 'compiler/rustc_error_codes')
7 files changed, 63 insertions, 24 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0312.md b/compiler/rustc_error_codes/src/error_codes/E0312.md index cb090d01382..c5f7cf2e337 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0312.md +++ b/compiler/rustc_error_codes/src/error_codes/E0312.md @@ -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)" diff --git a/compiler/rustc_error_codes/src/error_codes/E0477.md b/compiler/rustc_error_codes/src/error_codes/E0477.md index 9cfefb1de63..c6be8dc705e 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0477.md +++ b/compiler/rustc_error_codes/src/error_codes/E0477.md @@ -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> { diff --git a/compiler/rustc_error_codes/src/error_codes/E0495.md b/compiler/rustc_error_codes/src/error_codes/E0495.md index f956237b80b..cd10e719312 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0495.md +++ b/compiler/rustc_error_codes/src/error_codes/E0495.md @@ -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, diff --git a/compiler/rustc_error_codes/src/error_codes/E0623.md b/compiler/rustc_error_codes/src/error_codes/E0623.md index 1290edd0a0e..34db641bb90 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0623.md +++ b/compiler/rustc_error_codes/src/error_codes/E0623.md @@ -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; +} +impl<'long: 'short, 'short, T> Convert<'long, 'short> for T { + fn cast(&'long self) -> &'short T { + self + } } -fn bar<'short>(c: Foo<'short>, l: &'short isize) { - let _: Foo<'short> = c; // ok! +fn badboi<'out, T>(x: Foo<'out, 'out, T>, sadness: &'out T) -> &'out T { + sadness.cast() } ``` diff --git a/compiler/rustc_error_codes/src/error_codes/E0713.md b/compiler/rustc_error_codes/src/error_codes/E0713.md index 9361046943f..9b1b77f3bc7 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0713.md +++ b/compiler/rustc_error_codes/src/error_codes/E0713.md @@ -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> { diff --git a/compiler/rustc_error_codes/src/error_codes/E0759.md b/compiler/rustc_error_codes/src/error_codes/E0759.md index 6b16a7d415a..ce5d42b3c7f 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0759.md +++ b/compiler/rustc_error_codes/src/error_codes/E0759.md @@ -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! diff --git a/compiler/rustc_error_codes/src/error_codes/E0772.md b/compiler/rustc_error_codes/src/error_codes/E0772.md index 3b73abaf776..5ffffd5112d 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0772.md +++ b/compiler/rustc_error_codes/src/error_codes/E0772.md @@ -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 {} |
