about summary refs log tree commit diff
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2022-04-26 19:49:00 -0700
committerScott McMurray <scottmcm@users.noreply.github.com>2022-04-30 18:10:01 -0700
commitb317ec1697fa3d8d095ea99b7180ae6eab9f77af (patch)
tree88c0c7a9aa35e39ce516d26615f92851866a6fdc
parent9b5766cd24554427c2f5fb283c1f09718804cfd0 (diff)
downloadrust-b317ec1697fa3d8d095ea99b7180ae6eab9f77af.tar.gz
rust-b317ec1697fa3d8d095ea99b7180ae6eab9f77af.zip
Feature-gate `do yeet` inside `cfg`s too
-rw-r--r--compiler/rustc_ast_passes/src/feature_gate.rs9
-rw-r--r--src/test/ui/feature-gates/feature-gate-yeet_expr-in-cfg.rs19
-rw-r--r--src/test/ui/feature-gates/feature-gate-yeet_expr-in-cfg.stderr21
3 files changed, 41 insertions, 8 deletions
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 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
             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 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
     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<i32> {
+    #[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 <https://github.com/rust-lang/rust/issues/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 <https://github.com/rust-lang/rust/issues/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`.