Fix feature gating for new try bikeshed expressions

This commit is contained in:
Scott McMurray 2026-02-11 22:19:26 -08:00
parent 08a4ce529f
commit 6afebcc4dd
5 changed files with 47 additions and 7 deletions

View file

@ -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
}

View file

@ -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`.

View file

@ -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
}

View file

@ -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