about summary refs log tree commit diff
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2023-04-29 14:57:26 +0200
committerest31 <MTest31@outlook.com>2023-05-05 21:44:48 +0200
commit83b4df4e611961373ffaf4bfcd9f8940a4f37c09 (patch)
tree85d737c61f42bb70cef306a56292c83abcf25ab9
parent5eb29c7f49c2d99e9bfc778f30984f7fdcf5fc08 (diff)
downloadrust-83b4df4e611961373ffaf4bfcd9f8940a4f37c09.tar.gz
rust-83b4df4e611961373ffaf4bfcd9f8940a4f37c09.zip
Add feature gate
-rw-r--r--compiler/rustc_ast_passes/src/feature_gate.rs1
-rw-r--r--compiler/rustc_feature/src/active.rs2
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs1
-rw-r--r--tests/ui/feature-gates/feature-gate-builtin_syntax.rs7
-rw-r--r--tests/ui/feature-gates/feature-gate-builtin_syntax.stderr12
-rw-r--r--tests/ui/offset-of/offset-of-builtin.rs4
-rw-r--r--tests/ui/parser/builtin-syntax.rs2
-rw-r--r--tests/ui/parser/builtin-syntax.stderr4
8 files changed, 29 insertions, 4 deletions
diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs
index b960671bf6e..3d5056d82c5 100644
--- a/compiler/rustc_ast_passes/src/feature_gate.rs
+++ b/compiler/rustc_ast_passes/src/feature_gate.rs
@@ -603,6 +603,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
     gate_all!(yeet_expr, "`do yeet` expression is experimental");
     gate_all!(dyn_star, "`dyn*` trait objects are experimental");
     gate_all!(const_closures, "const closures are experimental");
+    gate_all!(builtin_syntax, "`builtin #` syntax is unstable");
 
     if !visitor.features.negative_bounds {
         for &span in spans.get(&sym::negative_bounds).iter().copied().flatten() {
diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs
index 7e7df0e9584..a797dd94404 100644
--- a/compiler/rustc_feature/src/active.rs
+++ b/compiler/rustc_feature/src/active.rs
@@ -313,6 +313,8 @@ declare_features! (
     (active, async_closure, "1.37.0", Some(62290), None),
     /// Allows async functions to be declared, implemented, and used in traits.
     (active, async_fn_in_trait, "1.66.0", Some(91611), None),
+    /// Allows builtin # foo() syntax
+    (active, builtin_syntax, "CURRENT_RUSTC_VERSION", Some(110680), None),
     /// Allows `c"foo"` literals.
     (active, c_str_literals, "CURRENT_RUSTC_VERSION", Some(105723), None),
     /// Treat `extern "C"` function as nounwind.
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index b84a088a7b7..c1095512bd4 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -1782,6 +1782,7 @@ impl<'a> Parser<'a> {
                 .into_diagnostic(&self.sess.span_diagnostic);
             return Err(err);
         };
+        self.sess.gated_spans.gate(sym::builtin_syntax, ident.span);
         self.bump();
 
         self.expect(&TokenKind::OpenDelim(Delimiter::Parenthesis))?;
diff --git a/tests/ui/feature-gates/feature-gate-builtin_syntax.rs b/tests/ui/feature-gates/feature-gate-builtin_syntax.rs
new file mode 100644
index 00000000000..832bb5a96bc
--- /dev/null
+++ b/tests/ui/feature-gates/feature-gate-builtin_syntax.rs
@@ -0,0 +1,7 @@
+struct Foo {
+    v: u8,
+    w: u8,
+}
+fn main() {
+    builtin # offset_of(Foo, v); //~ ERROR `builtin #` syntax is unstable
+}
diff --git a/tests/ui/feature-gates/feature-gate-builtin_syntax.stderr b/tests/ui/feature-gates/feature-gate-builtin_syntax.stderr
new file mode 100644
index 00000000000..3bc7848f66d
--- /dev/null
+++ b/tests/ui/feature-gates/feature-gate-builtin_syntax.stderr
@@ -0,0 +1,12 @@
+error[E0658]: `builtin #` syntax is unstable
+  --> $DIR/feature-gate-builtin_syntax.rs:6:15
+   |
+LL |     builtin # offset_of(Foo, v);
+   |               ^^^^^^^^^
+   |
+   = note: see issue #110680 <https://github.com/rust-lang/rust/issues/110680> for more information
+   = help: add `#![feature(builtin_syntax)]` to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/offset-of/offset-of-builtin.rs b/tests/ui/offset-of/offset-of-builtin.rs
index dcc58e842a0..1be9899887b 100644
--- a/tests/ui/offset-of/offset-of-builtin.rs
+++ b/tests/ui/offset-of/offset-of-builtin.rs
@@ -1,9 +1,9 @@
+#![feature(builtin_syntax)]
+
 // For the exposed macro we already test these errors in the other files,
 // but this test helps to make sure the builtin construct also errors.
 // This has the same examples as offset-of-arg-count.rs
 
-
-
 fn main() {
     builtin # offset_of(NotEnoughArguments); //~ ERROR expected one of
 }
diff --git a/tests/ui/parser/builtin-syntax.rs b/tests/ui/parser/builtin-syntax.rs
index c0b91a58073..897dab8ec50 100644
--- a/tests/ui/parser/builtin-syntax.rs
+++ b/tests/ui/parser/builtin-syntax.rs
@@ -1,3 +1,5 @@
+#![feature(builtin_syntax)]
+
 fn main() {
     builtin # foobar(); //~ ERROR unknown `builtin #` construct
 }
diff --git a/tests/ui/parser/builtin-syntax.stderr b/tests/ui/parser/builtin-syntax.stderr
index 2679049fb5e..ee3764a6221 100644
--- a/tests/ui/parser/builtin-syntax.stderr
+++ b/tests/ui/parser/builtin-syntax.stderr
@@ -1,11 +1,11 @@
 error: unknown `builtin #` construct `foobar`
-  --> $DIR/builtin-syntax.rs:2:5
+  --> $DIR/builtin-syntax.rs:4:5
    |
 LL |     builtin # foobar();
    |     ^^^^^^^^^^^^^^^^
 
 error: expected identifier after `builtin #`
-  --> $DIR/builtin-syntax.rs:6:15
+  --> $DIR/builtin-syntax.rs:8:15
    |
 LL |     builtin # {}();
    |               ^