Skip to content

Commit 4272864

Browse files
committed
Feature gate 'yield ?' pre-expansion.
1 parent 60960a2 commit 4272864

File tree

6 files changed

+39
-6
lines changed

6 files changed

+39
-6
lines changed

src/libsyntax/feature_gate.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -2088,11 +2088,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
20882088
"type ascription is experimental");
20892089
}
20902090
}
2091-
ast::ExprKind::Yield(..) => {
2092-
gate_feature_post!(&self, generators,
2093-
e.span,
2094-
"yield syntax is experimental");
2095-
}
20962091
ast::ExprKind::TryBlock(_) => {
20972092
gate_feature_post!(&self, try_blocks, e.span, "`try` expression is experimental");
20982093
}
@@ -2464,6 +2459,13 @@ pub fn check_crate(krate: &ast::Crate,
24642459
"async closures are unstable"
24652460
));
24662461

2462+
for_each_in_lock(&sess.yield_spans, |span| gate_feature!(
2463+
&ctx,
2464+
generators,
2465+
*span,
2466+
"yield syntax is experimental"
2467+
));
2468+
24672469
let visitor = &mut PostExpansionVisitor {
24682470
context: &ctx,
24692471
builtin_attributes: &*BUILTIN_ATTRIBUTE_MAP,

src/libsyntax/parse/lexer/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ fn mk_sess(sm: Lrc<SourceMap>) -> ParseSess {
3434
param_attr_spans: Lock::new(Vec::new()),
3535
let_chains_spans: Lock::new(Vec::new()),
3636
async_closure_spans: Lock::new(Vec::new()),
37+
yield_spans: Lock::new(Vec::new()),
3738
injected_crate_name: Once::new(),
3839
}
3940
}

src/libsyntax/parse/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ pub struct ParseSess {
6262
pub let_chains_spans: Lock<Vec<Span>>,
6363
// Places where `async || ..` exprs were used and should be feature gated.
6464
pub async_closure_spans: Lock<Vec<Span>>,
65+
// Places where `yield e?` exprs were used and should be feature gated.
66+
pub yield_spans: Lock<Vec<Span>>,
6567
pub injected_crate_name: Once<Symbol>,
6668
}
6769

@@ -91,6 +93,7 @@ impl ParseSess {
9193
param_attr_spans: Lock::new(Vec::new()),
9294
let_chains_spans: Lock::new(Vec::new()),
9395
async_closure_spans: Lock::new(Vec::new()),
96+
yield_spans: Lock::new(Vec::new()),
9497
injected_crate_name: Once::new(),
9598
}
9699
}

src/libsyntax/parse/parser/expr.rs

+3
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,9 @@ impl<'a> Parser<'a> {
993993
} else {
994994
ex = ExprKind::Yield(None);
995995
}
996+
997+
let span = lo.to(hi);
998+
self.sess.yield_spans.borrow_mut().push(span);
996999
} else if self.eat_keyword(kw::Let) {
9971000
return self.parse_let_expr(attrs);
9981001
} else if is_span_rust_2018 && self.eat_keyword(kw::Await) {

src/test/ui/feature-gates/feature-gate-generators.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@ fn main() {
22
yield true; //~ ERROR yield syntax is experimental
33
//~^ ERROR yield statement outside of generator literal
44
}
5+
6+
#[cfg(FALSE)]
7+
fn foo() {
8+
yield; //~ ERROR yield syntax is experimental
9+
yield 0; //~ ERROR yield syntax is experimental
10+
}

src/test/ui/feature-gates/feature-gate-generators.stderr

+19-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,30 @@ LL | yield true;
77
= note: for more information, see https://github.com/rust-lang/rust/issues/43122
88
= help: add `#![feature(generators)]` to the crate attributes to enable
99

10+
error[E0658]: yield syntax is experimental
11+
--> $DIR/feature-gate-generators.rs:8:5
12+
|
13+
LL | yield;
14+
| ^^^^^
15+
|
16+
= note: for more information, see https://github.com/rust-lang/rust/issues/43122
17+
= help: add `#![feature(generators)]` to the crate attributes to enable
18+
19+
error[E0658]: yield syntax is experimental
20+
--> $DIR/feature-gate-generators.rs:9:5
21+
|
22+
LL | yield 0;
23+
| ^^^^^^^
24+
|
25+
= note: for more information, see https://github.com/rust-lang/rust/issues/43122
26+
= help: add `#![feature(generators)]` to the crate attributes to enable
27+
1028
error[E0627]: yield statement outside of generator literal
1129
--> $DIR/feature-gate-generators.rs:2:5
1230
|
1331
LL | yield true;
1432
| ^^^^^^^^^^
1533

16-
error: aborting due to 2 previous errors
34+
error: aborting due to 4 previous errors
1735

1836
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)