forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#119563 - compiler-errors:coroutine-resume, …
…r=oli-obk Check yield terminator's resume type in borrowck In borrowck, we didn't check that the lifetimes of the `TerminatorKind::Yield`'s `resume_place` were actually compatible with the coroutine's signature. That means that the lifetimes were totally going unchecked. Whoops! This PR implements this checking. Fixes rust-lang#119564 r? types
- Loading branch information
Showing
12 changed files
with
190 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#![feature(coroutine_trait)] | ||
#![feature(coroutines)] | ||
|
||
use std::ops::Coroutine; | ||
|
||
struct Contravariant<'a>(fn(&'a ())); | ||
struct Covariant<'a>(fn() -> &'a ()); | ||
|
||
fn bad1<'short, 'long: 'short>() -> impl Coroutine<Covariant<'short>> { | ||
|_: Covariant<'short>| { | ||
let a: Covariant<'long> = yield (); | ||
//~^ ERROR lifetime may not live long enough | ||
} | ||
} | ||
|
||
fn bad2<'short, 'long: 'short>() -> impl Coroutine<Contravariant<'long>> { | ||
|_: Contravariant<'long>| { | ||
let a: Contravariant<'short> = yield (); | ||
//~^ ERROR lifetime may not live long enough | ||
} | ||
} | ||
|
||
fn good1<'short, 'long: 'short>() -> impl Coroutine<Covariant<'long>> { | ||
|_: Covariant<'long>| { | ||
let a: Covariant<'short> = yield (); | ||
} | ||
} | ||
|
||
fn good2<'short, 'long: 'short>() -> impl Coroutine<Contravariant<'short>> { | ||
|_: Contravariant<'short>| { | ||
let a: Contravariant<'long> = yield (); | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/check-resume-ty-lifetimes-2.rs:11:16 | ||
| | ||
LL | fn bad1<'short, 'long: 'short>() -> impl Coroutine<Covariant<'short>> { | ||
| ------ ----- lifetime `'long` defined here | ||
| | | ||
| lifetime `'short` defined here | ||
LL | |_: Covariant<'short>| { | ||
LL | let a: Covariant<'long> = yield (); | ||
| ^^^^^^^^^^^^^^^^ type annotation requires that `'short` must outlive `'long` | ||
| | ||
= help: consider adding the following bound: `'short: 'long` | ||
help: consider adding 'move' keyword before the nested closure | ||
| | ||
LL | move |_: Covariant<'short>| { | ||
| ++++ | ||
|
||
error: lifetime may not live long enough | ||
--> $DIR/check-resume-ty-lifetimes-2.rs:18:40 | ||
| | ||
LL | fn bad2<'short, 'long: 'short>() -> impl Coroutine<Contravariant<'long>> { | ||
| ------ ----- lifetime `'long` defined here | ||
| | | ||
| lifetime `'short` defined here | ||
LL | |_: Contravariant<'long>| { | ||
LL | let a: Contravariant<'short> = yield (); | ||
| ^^^^^^^^ yielding this value requires that `'short` must outlive `'long` | ||
| | ||
= help: consider adding the following bound: `'short: 'long` | ||
help: consider adding 'move' keyword before the nested closure | ||
| | ||
LL | move |_: Contravariant<'long>| { | ||
| ++++ | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#![feature(coroutine_trait)] | ||
#![feature(coroutines)] | ||
#![allow(unused)] | ||
|
||
use std::ops::Coroutine; | ||
use std::ops::CoroutineState; | ||
use std::pin::pin; | ||
|
||
fn mk_static(s: &str) -> &'static str { | ||
let mut storage: Option<&'static str> = None; | ||
|
||
let mut coroutine = pin!(|_: &str| { | ||
let x: &'static str = yield (); | ||
//~^ ERROR lifetime may not live long enough | ||
storage = Some(x); | ||
}); | ||
|
||
coroutine.as_mut().resume(s); | ||
coroutine.as_mut().resume(s); | ||
|
||
storage.unwrap() | ||
} | ||
|
||
fn main() { | ||
let s = mk_static(&String::from("hello, world")); | ||
println!("{s}"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/check-resume-ty-lifetimes.rs:13:16 | ||
| | ||
LL | fn mk_static(s: &str) -> &'static str { | ||
| - let's call the lifetime of this reference `'1` | ||
... | ||
LL | let x: &'static str = yield (); | ||
| ^^^^^^^^^^^^ type annotation requires that `'1` must outlive `'static` | ||
|
||
error: aborting due to 1 previous error | ||
|