Feature gate 'yield ?' pre-expansion.

This commit is contained in:
Mazdak Farrokhzad 2019-08-14 05:44:32 +02:00
parent 9dd5c19199
commit 4087fc583e
5 changed files with 38 additions and 6 deletions

View file

@ -2088,11 +2088,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
"type ascription is experimental");
}
}
ast::ExprKind::Yield(..) => {
gate_feature_post!(&self, generators,
e.span,
"yield syntax is experimental");
}
ast::ExprKind::TryBlock(_) => {
gate_feature_post!(&self, try_blocks, e.span, "`try` expression is experimental");
}
@ -2464,6 +2459,13 @@ pub fn check_crate(krate: &ast::Crate,
"async closures are unstable"
));
for_each_in_lock(&sess.yield_spans, |span| gate_feature!(
&ctx,
generators,
*span,
"yield syntax is experimental"
));
let visitor = &mut PostExpansionVisitor {
context: &ctx,
builtin_attributes: &*BUILTIN_ATTRIBUTE_MAP,

View file

@ -63,6 +63,8 @@ pub struct ParseSess {
pub let_chains_spans: Lock<Vec<Span>>,
// Places where `async || ..` exprs were used and should be feature gated.
pub async_closure_spans: Lock<Vec<Span>>,
// Places where `yield e?` exprs were used and should be feature gated.
pub yield_spans: Lock<Vec<Span>>,
pub injected_crate_name: Once<Symbol>,
}
@ -92,6 +94,7 @@ impl ParseSess {
param_attr_spans: Lock::new(Vec::new()),
let_chains_spans: Lock::new(Vec::new()),
async_closure_spans: Lock::new(Vec::new()),
yield_spans: Lock::new(Vec::new()),
injected_crate_name: Once::new(),
}
}

View file

@ -997,6 +997,9 @@ impl<'a> Parser<'a> {
} else {
ex = ExprKind::Yield(None);
}
let span = lo.to(hi);
self.sess.yield_spans.borrow_mut().push(span);
} else if self.eat_keyword(kw::Let) {
return self.parse_let_expr(attrs);
} else if is_span_rust_2018 && self.eat_keyword(kw::Await) {

View file

@ -2,3 +2,9 @@ fn main() {
yield true; //~ ERROR yield syntax is experimental
//~^ ERROR yield statement outside of generator literal
}
#[cfg(FALSE)]
fn foo() {
yield; //~ ERROR yield syntax is experimental
yield 0; //~ ERROR yield syntax is experimental
}

View file

@ -7,12 +7,30 @@ LL | yield true;
= note: for more information, see https://github.com/rust-lang/rust/issues/43122
= help: add `#![feature(generators)]` to the crate attributes to enable
error[E0658]: yield syntax is experimental
--> $DIR/feature-gate-generators.rs:8:5
|
LL | yield;
| ^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/43122
= help: add `#![feature(generators)]` to the crate attributes to enable
error[E0658]: yield syntax is experimental
--> $DIR/feature-gate-generators.rs:9:5
|
LL | yield 0;
| ^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/43122
= help: add `#![feature(generators)]` to the crate attributes to enable
error[E0627]: yield statement outside of generator literal
--> $DIR/feature-gate-generators.rs:2:5
|
LL | yield true;
| ^^^^^^^^^^
error: aborting due to 2 previous errors
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0658`.