Rollup merge of #55013 - matthewjasper:propagate-generator-bounds, r=nikomatsakis

[NLL] Propagate bounds from generators

This used to only be done for closures.
This commit is contained in:
kennytm 2018-10-19 16:48:36 +08:00
commit 0724efd9a1
No known key found for this signature in database
GPG key ID: FEF6C8051D0E013C
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() {}