diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index add9955b184..0e8af549692 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -619,14 +619,6 @@ fn visit_expr(&mut self, e: &'a ast::Expr) { ast::ExprKind::TryBlock(_) => { gate_feature_post!(&self, try_blocks, e.span, "`try` expression is experimental"); } - ast::ExprKind::Yeet(_) => { - gate_feature_post!( - &self, - yeet_expr, - e.span, - "`do yeet` expression is experimental" - ); - } ast::ExprKind::Block(_, Some(label)) => { gate_feature_post!( &self, @@ -791,6 +783,7 @@ macro_rules! gate_all { gate_all!(inline_const, "inline-const is experimental"); gate_all!(inline_const_pat, "inline-const in pattern position is experimental"); gate_all!(associated_const_equality, "associated const equality is incomplete"); + gate_all!(yeet_expr, "`do yeet` expression is experimental"); // All uses of `gate_all!` below this point were added in #65742, // and subsequently disabled (with the non-early gating readded). diff --git a/src/test/ui/feature-gates/feature-gate-yeet_expr-in-cfg.rs b/src/test/ui/feature-gates/feature-gate-yeet_expr-in-cfg.rs new file mode 100644 index 00000000000..a33bd34508c --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-yeet_expr-in-cfg.rs @@ -0,0 +1,19 @@ +// compile-flags: --edition 2021 + +pub fn demo() -> Option { + #[cfg(nope)] + { + do yeet //~ ERROR `do yeet` expression is experimental + } + + Some(1) +} + +#[cfg(nope)] +pub fn alternative() -> Result<(), String> { + do yeet "hello"; //~ ERROR `do yeet` expression is experimental +} + +fn main() { + demo(); +} diff --git a/src/test/ui/feature-gates/feature-gate-yeet_expr-in-cfg.stderr b/src/test/ui/feature-gates/feature-gate-yeet_expr-in-cfg.stderr new file mode 100644 index 00000000000..f90c379bdaf --- /dev/null +++ b/src/test/ui/feature-gates/feature-gate-yeet_expr-in-cfg.stderr @@ -0,0 +1,21 @@ +error[E0658]: `do yeet` expression is experimental + --> $DIR/feature-gate-yeet_expr-in-cfg.rs:6:9 + | +LL | do yeet + | ^^^^^^^ + | + = note: see issue #96373 for more information + = help: add `#![feature(yeet_expr)]` to the crate attributes to enable + +error[E0658]: `do yeet` expression is experimental + --> $DIR/feature-gate-yeet_expr-in-cfg.rs:14:5 + | +LL | do yeet "hello"; + | ^^^^^^^^^^^^^^^ + | + = note: see issue #96373 for more information + = help: add `#![feature(yeet_expr)]` to the crate attributes to enable + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0658`.