Skip to content

Commit 83b4df4

Browse files
committed
Add feature gate
1 parent 5eb29c7 commit 83b4df4

File tree

8 files changed

+29
-4
lines changed

8 files changed

+29
-4
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
603603
gate_all!(yeet_expr, "`do yeet` expression is experimental");
604604
gate_all!(dyn_star, "`dyn*` trait objects are experimental");
605605
gate_all!(const_closures, "const closures are experimental");
606+
gate_all!(builtin_syntax, "`builtin #` syntax is unstable");
606607

607608
if !visitor.features.negative_bounds {
608609
for &span in spans.get(&sym::negative_bounds).iter().copied().flatten() {

compiler/rustc_feature/src/active.rs

+2
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ declare_features! (
313313
(active, async_closure, "1.37.0", Some(62290), None),
314314
/// Allows async functions to be declared, implemented, and used in traits.
315315
(active, async_fn_in_trait, "1.66.0", Some(91611), None),
316+
/// Allows builtin # foo() syntax
317+
(active, builtin_syntax, "CURRENT_RUSTC_VERSION", Some(110680), None),
316318
/// Allows `c"foo"` literals.
317319
(active, c_str_literals, "CURRENT_RUSTC_VERSION", Some(105723), None),
318320
/// Treat `extern "C"` function as nounwind.

compiler/rustc_parse/src/parser/expr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1782,6 +1782,7 @@ impl<'a> Parser<'a> {
17821782
.into_diagnostic(&self.sess.span_diagnostic);
17831783
return Err(err);
17841784
};
1785+
self.sess.gated_spans.gate(sym::builtin_syntax, ident.span);
17851786
self.bump();
17861787

17871788
self.expect(&TokenKind::OpenDelim(Delimiter::Parenthesis))?;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
struct Foo {
2+
v: u8,
3+
w: u8,
4+
}
5+
fn main() {
6+
builtin # offset_of(Foo, v); //~ ERROR `builtin #` syntax is unstable
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: `builtin #` syntax is unstable
2+
--> $DIR/feature-gate-builtin_syntax.rs:6:15
3+
|
4+
LL | builtin # offset_of(Foo, v);
5+
| ^^^^^^^^^
6+
|
7+
= note: see issue #110680 <https://github.com/rust-lang/rust/issues/110680> for more information
8+
= help: add `#![feature(builtin_syntax)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.

tests/ui/offset-of/offset-of-builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
#![feature(builtin_syntax)]
2+
13
// For the exposed macro we already test these errors in the other files,
24
// but this test helps to make sure the builtin construct also errors.
35
// This has the same examples as offset-of-arg-count.rs
46

5-
6-
77
fn main() {
88
builtin # offset_of(NotEnoughArguments); //~ ERROR expected one of
99
}

tests/ui/parser/builtin-syntax.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![feature(builtin_syntax)]
2+
13
fn main() {
24
builtin # foobar(); //~ ERROR unknown `builtin #` construct
35
}

tests/ui/parser/builtin-syntax.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: unknown `builtin #` construct `foobar`
2-
--> $DIR/builtin-syntax.rs:2:5
2+
--> $DIR/builtin-syntax.rs:4:5
33
|
44
LL | builtin # foobar();
55
| ^^^^^^^^^^^^^^^^
66

77
error: expected identifier after `builtin #`
8-
--> $DIR/builtin-syntax.rs:6:15
8+
--> $DIR/builtin-syntax.rs:8:15
99
|
1010
LL | builtin # {}();
1111
| ^

0 commit comments

Comments
 (0)