Propagate bounds from generators

This commit is contained in:
Matthew Jasper 2018-10-12 15:16:29 +01:00
parent 121320d523
commit ef1a40d5fe
6 changed files with 57 additions and 19 deletions

View file

@ -0,0 +1,12 @@
error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/generator-region-requirements.rs:15:51
|
LL | fn dangle(x: &mut i32) -> &'static mut i32 {
| -------- help: add explicit lifetime `'static` to the type of `x`: `&'static mut i32`
...
LL | GeneratorState::Complete(c) => return c,
| ^ lifetime `'static` required
error: aborting due to previous error
For more information about this error, try `rustc --explain E0621`.

View file

@ -0,0 +1,12 @@
error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/generator-region-requirements.rs:11:9
|
LL | fn dangle(x: &mut i32) -> &'static mut i32 {
| -------- help: add explicit lifetime `'static` to the type of `x`: `&'static mut i32`
...
LL | x
| ^ lifetime `'static` required
error: aborting due to previous error
For more information about this error, try `rustc --explain E0621`.

View file

@ -0,0 +1,21 @@
// revisions: ast nll
// ignore-compare-mode-nll
#![feature(generators, generator_trait)]
#![cfg_attr(nll, feature(nll))]
use std::ops::{Generator, GeneratorState};
fn dangle(x: &mut i32) -> &'static mut i32 {
let mut g = || {
yield;
x
};
loop {
match unsafe { g.resume() } {
GeneratorState::Complete(c) => return c,
GeneratorState::Yielded(_) => (),
}
}
}
fn main() {}