Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,11 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
fn visit_expr(&mut self, e: &'a ast::Expr) {
match e.kind {
ast::ExprKind::TryBlock(_, None) => {
// `try { ... }` is old and is only gated post-expansion here.
gate!(&self, try_blocks, e.span, "`try` expression is experimental");
}
ast::ExprKind::TryBlock(_, Some(_)) => {
gate!(
&self,
try_blocks_heterogeneous,
e.span,
"`try bikeshed` expression is experimental"
);
// `try_blocks_heterogeneous` is new, and gated pre-expansion instead.
}
ast::ExprKind::Lit(token::Lit {
kind: token::LitKind::Float | token::LitKind::Integer,
Expand Down Expand Up @@ -499,6 +495,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
half_open_range_patterns_in_slices,
"half-open range patterns in slices are unstable"
);
gate_all!(try_blocks_heterogeneous, "`try bikeshed` expression is experimental");
gate_all!(yeet_expr, "`do yeet` expression is experimental");
gate_all!(const_closures, "const closures are experimental");
gate_all!(builtin_syntax, "`builtin #` syntax is unstable");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ pub fn main() {
x
};
assert_eq!(try_result, Some(5));

// The heterogenous form is new, so is gated even under a `cfg(false)`.
// See <https://github.com/rust-lang/rust/issues/152501>

#[cfg(false)]
try bikeshed () {}
//~^ error `try bikeshed` expression is experimental
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ LL | | };
= help: add `#![feature(try_blocks_heterogeneous)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

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

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0658`.
12 changes: 12 additions & 0 deletions tests/ui/try-block/try-block-homogeneous-pre-expansion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@ check-pass
//@ edition: 2018

// For historical reasons this is only a warning, not an error.
// See <https://github.com/rust-lang/rust/issues/152501>

fn main() {
#[cfg(false)]
try {}
//~^ warn `try` blocks are unstable
//~| warn unstable syntax can change at any point
}
14 changes: 14 additions & 0 deletions tests/ui/try-block/try-block-homogeneous-pre-expansion.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
warning: `try` blocks are unstable
--> $DIR/try-block-homogeneous-pre-expansion.rs:9:5
|
LL | try {}
| ^^^^^^
|
= note: see issue #31436 <https://github.com/rust-lang/rust/issues/31436> for more information
= help: add `#![feature(try_blocks)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
= warning: unstable syntax can change at any point in the future, causing a hard error!
= note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860>

warning: 1 warning emitted

Loading