Skip to content

Commit

Permalink
Add feature gate
Browse files Browse the repository at this point in the history
  • Loading branch information
est31 committed May 5, 2023
1 parent 5eb29c7 commit 83b4df4
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))?;
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/feature-gates/feature-gate-builtin_syntax.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
struct Foo {
v: u8,
w: u8,
}
fn main() {
builtin # offset_of(Foo, v); //~ ERROR `builtin #` syntax is unstable
}
12 changes: 12 additions & 0 deletions tests/ui/feature-gates/feature-gate-builtin_syntax.stderr
Original file line number Diff line number Diff line change
@@ -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`.
4 changes: 2 additions & 2 deletions tests/ui/offset-of/offset-of-builtin.rs
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/parser/builtin-syntax.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(builtin_syntax)]

fn main() {
builtin # foobar(); //~ ERROR unknown `builtin #` construct
}
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/parser/builtin-syntax.stderr
Original file line number Diff line number Diff line change
@@ -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 # {}();
| ^
Expand Down

0 comments on commit 83b4df4

Please sign in to comment.