Fix feature gating for new try bikeshed expressions
This commit is contained in:
parent
08a4ce529f
commit
6afebcc4dd
5 changed files with 47 additions and 7 deletions
|
|
@ -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,
|
||||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
tests/ui/try-block/try-block-homogeneous-pre-expansion.rs
Normal file
12
tests/ui/try-block/try-block-homogeneous-pre-expansion.rs
Normal 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
|
||||
}
|
||||
|
|
@ -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…
Add table
Add a link
Reference in a new issue