Skip to content

Commit 7cec0d7

Browse files
committed
Add feature gate for unnamed_fields
1 parent ddcee6f commit 7cec0d7

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,21 @@ impl<'a> PostExpansionVisitor<'a> {
300300
}
301301

302302
impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
303+
fn visit_field_def(&mut self, s: &'a ast::FieldDef) {
304+
match s.variant {
305+
ast::FieldVariant::Unnamed(_) => {
306+
gate_feature_post!(
307+
&self,
308+
unnamed_fields,
309+
s.span,
310+
"unnamed fields are not yet fully implemented"
311+
)
312+
}
313+
_ => {}
314+
}
315+
visit::walk_field_def(self, s);
316+
}
317+
303318
fn visit_attribute(&mut self, attr: &ast::Attribute) {
304319
let attr_info =
305320
attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name)).map(|a| **a);
@@ -692,6 +707,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
692707
gate_all!(destructuring_assignment, "destructuring assignments are unstable");
693708
}
694709
gate_all!(pub_macro_rules, "`pub` on `macro_rules` items is unstable");
710+
gate_all!(unnamed_fields, "unnamed fields are not yet fully implemented");
695711

696712
// All uses of `gate_all!` below this point were added in #65742,
697713
// and subsequently disabled (with the non-early gating readded).

compiler/rustc_feature/src/active.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,9 @@ declare_features! (
642642
/// Allows `extern "wasm" fn`
643643
(active, wasm_abi, "1.53.0", Some(83788), None),
644644

645+
/// Allows unnamed fields of struct and union type
646+
(active, unnamed_fields, "1.53.0", Some(49804), None),
647+
645648
// -------------------------------------------------------------------------
646649
// feature-group-end: actual feature gates
647650
// -------------------------------------------------------------------------
@@ -669,6 +672,7 @@ pub const INCOMPLETE_FEATURES: &[Symbol] = &[
669672
sym::const_generics_defaults,
670673
sym::inherent_associated_types,
671674
sym::type_alias_impl_trait,
675+
sym::unnamed_fields,
672676
];
673677

674678
/// Some features are not allowed to be used together at the same time, if

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,7 @@ symbols! {
12541254
unix,
12551255
unlikely,
12561256
unmarked_api,
1257+
unnamed_fields,
12571258
unpin,
12581259
unreachable,
12591260
unreachable_code,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
struct Foo {
2+
_: struct { //~ ERROR unnamed fields are not yet fully implemented
3+
foo: u8
4+
}
5+
}
6+
7+
union Bar {
8+
_: union { //~ ERROR unnamed fields are not yet fully implemented
9+
bar: u8
10+
}
11+
}
12+
13+
struct S;
14+
struct Baz {
15+
_: S //~ ERROR unnamed fields are not yet fully implemented
16+
}

0 commit comments

Comments
 (0)