Skip to content

Commit 4087fc5

Browse files
committed
Feature gate 'yield ?' pre-expansion.
1 parent 9dd5c19 commit 4087fc5

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-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/mod.rs

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

@@ -92,6 +94,7 @@ impl ParseSess {
9294
param_attr_spans: Lock::new(Vec::new()),
9395
let_chains_spans: Lock::new(Vec::new()),
9496
async_closure_spans: Lock::new(Vec::new()),
97+
yield_spans: Lock::new(Vec::new()),
9598
injected_crate_name: Once::new(),
9699
}
97100
}

src/libsyntax/parse/parser/expr.rs

+3
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,9 @@ impl<'a> Parser<'a> {
997997
} else {
998998
ex = ExprKind::Yield(None);
999999
}
1000+
1001+
let span = lo.to(hi);
1002+
self.sess.yield_spans.borrow_mut().push(span);
10001003
} else if self.eat_keyword(kw::Let) {
10011004
return self.parse_let_expr(attrs);
10021005
} 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)