Skip to content

Commit 4269210

Browse files
authored
Rollup merge of #152519 - scottmcm:fix-152501, r=fmease
Fix feature gating for new `try bikeshed` expressions r? fmease Fixes #152501
2 parents 8b036c7 + 6afebcc commit 4269210

File tree

5 files changed

+47
-7
lines changed

5 files changed

+47
-7
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,15 +338,11 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
338338
fn visit_expr(&mut self, e: &'a ast::Expr) {
339339
match e.kind {
340340
ast::ExprKind::TryBlock(_, None) => {
341+
// `try { ... }` is old and is only gated post-expansion here.
341342
gate!(&self, try_blocks, e.span, "`try` expression is experimental");
342343
}
343344
ast::ExprKind::TryBlock(_, Some(_)) => {
344-
gate!(
345-
&self,
346-
try_blocks_heterogeneous,
347-
e.span,
348-
"`try bikeshed` expression is experimental"
349-
);
345+
// `try_blocks_heterogeneous` is new, and gated pre-expansion instead.
350346
}
351347
ast::ExprKind::Lit(token::Lit {
352348
kind: token::LitKind::Float | token::LitKind::Integer,
@@ -522,6 +518,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
522518
half_open_range_patterns_in_slices,
523519
"half-open range patterns in slices are unstable"
524520
);
521+
gate_all!(try_blocks_heterogeneous, "`try bikeshed` expression is experimental");
525522
gate_all!(yeet_expr, "`do yeet` expression is experimental");
526523
gate_all!(const_closures, "const closures are experimental");
527524
gate_all!(builtin_syntax, "`builtin #` syntax is unstable");

tests/ui/feature-gates/feature-gate-try_blocks_heterogeneous.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,11 @@ pub fn main() {
66
x
77
};
88
assert_eq!(try_result, Some(5));
9+
10+
// The heterogenous form is new, so is gated even under a `cfg(false)`.
11+
// See <https://github.com/rust-lang/rust/issues/152501>
12+
13+
#[cfg(false)]
14+
try bikeshed () {}
15+
//~^ error `try bikeshed` expression is experimental
916
}

tests/ui/feature-gates/feature-gate-try_blocks_heterogeneous.stderr

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ LL | | };
1212
= help: add `#![feature(try_blocks_heterogeneous)]` to the crate attributes to enable
1313
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1414

15-
error: aborting due to 1 previous error
15+
error[E0658]: `try bikeshed` expression is experimental
16+
--> $DIR/feature-gate-try_blocks_heterogeneous.rs:14:5
17+
|
18+
LL | try bikeshed () {}
19+
| ^^^^^^^^^^^^^^^^^^
20+
|
21+
= note: see issue #149488 <https://github.com/rust-lang/rust/issues/149488> for more information
22+
= help: add `#![feature(try_blocks_heterogeneous)]` to the crate attributes to enable
23+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
24+
25+
error: aborting due to 2 previous errors
1626

1727
For more information about this error, try `rustc --explain E0658`.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ check-pass
2+
//@ edition: 2018
3+
4+
// For historical reasons this is only a warning, not an error.
5+
// See <https://github.com/rust-lang/rust/issues/152501>
6+
7+
fn main() {
8+
#[cfg(false)]
9+
try {}
10+
//~^ warn `try` blocks are unstable
11+
//~| warn unstable syntax can change at any point
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
warning: `try` blocks are unstable
2+
--> $DIR/try-block-homogeneous-pre-expansion.rs:9:5
3+
|
4+
LL | try {}
5+
| ^^^^^^
6+
|
7+
= note: see issue #31436 <https://github.com/rust-lang/rust/issues/31436> for more information
8+
= help: add `#![feature(try_blocks)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
= warning: unstable syntax can change at any point in the future, causing a hard error!
11+
= note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860>
12+
13+
warning: 1 warning emitted
14+

0 commit comments

Comments
 (0)