Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d59696d

Browse files
committedSep 24, 2024·
Introduce default_field_values feature
Initial implementation of `#[feature(default_field_values]`, proposed in rust-lang/rfcs#3681. Support default fields in enum struct variant Allow default values in an enum struct variant definition: ```rust pub enum Bar { Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Allow using `..` without a base on an enum struct variant ```rust Bar::Foo { .. } ``` `#[derive(Default)]` doesn't account for these as it is still gating `#[default]` only being allowed on unit variants. Support `#[derive(Default)]` on enum struct variants with all defaulted fields ```rust pub enum Bar { #[default] Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Check for missing fields in typeck instead of mir_build. Expand test with `const` param case (needs `generic_const_exprs` enabled). Properly instantiate MIR const The following works: ```rust struct S<A> { a: Vec<A> = Vec::new(), } S::<i32> { .. } ```
1 parent 648d024 commit d59696d

File tree

60 files changed

+873
-290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+873
-290
lines changed
 

‎compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2995,6 +2995,7 @@ pub struct FieldDef {
29952995
pub ident: Option<Ident>,
29962996

29972997
pub ty: P<Ty>,
2998+
pub default: Option<AnonConst>,
29982999
pub is_placeholder: bool,
29993000
}
30003001

‎compiler/rustc_ast/src/mut_visit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,12 +1048,13 @@ pub fn walk_flat_map_field_def<T: MutVisitor>(
10481048
visitor: &mut T,
10491049
mut fd: FieldDef,
10501050
) -> SmallVec<[FieldDef; 1]> {
1051-
let FieldDef { span, ident, vis, id, ty, attrs, is_placeholder: _ } = &mut fd;
1051+
let FieldDef { span, ident, vis, id, ty, attrs, is_placeholder: _, default } = &mut fd;
10521052
visitor.visit_id(id);
10531053
visit_attrs(visitor, attrs);
10541054
visitor.visit_vis(vis);
10551055
visit_opt(ident, |ident| visitor.visit_ident(ident));
10561056
visitor.visit_ty(ty);
1057+
visit_opt(default, |default| visitor.visit_anon_const(default));
10571058
visitor.visit_span(span);
10581059
smallvec![fd]
10591060
}

0 commit comments

Comments
 (0)
Please sign in to comment.