Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking issue for RFC 3681: Default field values #132162

Open
6 tasks
estebank opened this issue Oct 25, 2024 · 0 comments
Open
6 tasks

Tracking issue for RFC 3681: Default field values #132162

estebank opened this issue Oct 25, 2024 · 0 comments
Labels
B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. F-default_field_values `#![feature(default_field_values)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

estebank commented Oct 25, 2024

This is a tracking issue for the RFC "3681" (rust-lang/rfcs#3681).
The feature gate for the issue is #![feature(default_field_values)].

Allow struct definitions to provide default values for individual fields and
thereby allowing those to be omitted from initializers. When deriving Default,
the provided values will then be used. For example:

#[derive(Default)]
struct Pet {
    name: Option<String>, // impl Default for Pet will use Default::default() for name
    age: i128 = 42, // impl Default for Pet will use the literal 42 for age
}

let valid = Pet { name: None, .. };
assert_eq!(valid.age, 42);
let default = Pet::default();
assert_eq!(default.age, 42);

let invalid = Pet { .. };

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Discussion comments will get marked as off-topic or deleted.
Repeated discussions on the tracking issue may lead to the tracking issue getting locked.

Steps

Unresolved Questions

XXX --- list all the "unresolved questions" found in the RFC to ensure they are
not forgotten

Implementation history

@estebank estebank added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. F-default_field_values `#![feature(default_field_values)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Oct 25, 2024
@estebank estebank changed the title Tracking Issue for rust-lang/rfcs#3681 Tracking Issue for rust-lang/rfcs#3681: default field values Oct 25, 2024
@fmease fmease changed the title Tracking Issue for rust-lang/rfcs#3681: default field values Tracking issue for RFC 3681: Default field values Oct 26, 2024
@traviscross traviscross added the B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. label Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. F-default_field_values `#![feature(default_field_values)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants