-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Implementation Issue for RFC 2528: type-changing struct update syntax #86555 #86618
Comments
@rustbot assign @kolharsam They expressed an interest in this! |
@rustbot claim |
Here are some mentoring notes. PR 0: Create the feature gateWe need a feature gate to control when users are accessing this feature. Instructions for adding a feature gate are here: https://rustc-dev-guide.rust-lang.org/feature-gates.html#adding-a-feature-gate Adding a feature gate can and should be its own PR! |
PR 1: Write up some testsA good next step is to open a PR creating a directory in |
PR 2: Update the type checkerFirst off, We create this type The following code checks each of the fields provided by the user, ensuring their names match and so forth. This code doesn't have to change for the most part: One thing we might want to do though is to return or otherwise get access to the list of 'remaining fields' (those whose types were not specified by the user): After checking the types of the fields, we check if there is a "base expression" ( If so, we check that it has the type What we want to be know is that:
Right now, we don't have any explicit "field-by-field" code, beacuse when we check that the type of the base expression is equal to However, we do have code that computes the various FRU here stands for "functional record update", btw. Anyway, these types today are stored into the Because this is not backwards compatible, we have to make our changes conditional on the feature gate being enabled. If it is not enabled, the code should do the same as it does today. But it is IS enabled, we should remove this check and instead enforce that:
The final check ("that they are a subtype") is done by calling |
@nikomatsakis Have made a respective PR for the same here: #86646 |
@nikomatsakis I've made a PR with a failing test here: #86660. Please let me know if there are any other test cases that need to be added because I wasn't really sure about what else could've been added as a test. |
…ackh726 add feature flag for `type_changing_struct_update` This implements the PR0 part of the mentoring notes within rust-lang#86618. overrides the previous inactive rust-lang#86646 pr. r? `@nikomatsakis`
…ackh726 add feature flag for `type_changing_struct_update` This implements the PR0 part of the mentoring notes within rust-lang#86618. overrides the previous inactive rust-lang#86646 pr. r? ``@nikomatsakis``
…ackh726 add feature flag for `type_changing_struct_update` This implements the PR0 part of the mentoring notes within rust-lang#86618. overrides the previous inactive rust-lang#86646 pr. r? ```@nikomatsakis```
implement rfc-2528 type_changing-struct-update This PR implement rfc2528-type_changing-struct-update. The main change process is as follows: 1. Move the processing part of `base_expr` into `check_expr_struct_fields` to avoid returning `remaining_fields` (a relatively complex hash table) 2. Before performing the type consistency check(`check_expr_has_type_or_error`), if the `type_changing_struct_update` feature is set, enter a different processing flow, otherwise keep the original flow 3. In the case of the same structure definition, check each field in `remaining_fields`. If the field in `base_expr` is not the suptype of the field in `adt_ty`, an error(`FeildMisMatch`) will be reported. The MIR part does not need to be changed, because only the items contained in `remaining_fields` will be extracted from `base_expr` when MIR is generated. This means that fields with different types in `base_expr` will not be used Updates rust-lang#86618 cc `@nikomatsakis`
The current implementation seems to interfere with with type inference: #![feature(type_changing_struct_update)]
#[derive(Default)]
struct A {
x: i32
}
fn main() {
let a = A{
..Default::default()
};
}
|
I don't believe we've implemented this feature yet =) there are mentoring notes here. I know that someone was looking into it, maybe it was @kolharsam? (If I failed to get back to you, @kolharsam, sorry, are you still interested?) |
@nikomatsakis Yes, I was looking into it, and I'm still interested in continuing the work. |
The feature has actually been implemented in #90035, if I'm not mistaken. It already seems to work: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=a84582797c0337611b94e3c5afaeba91. |
We think this is implemented now, so closing this issue. #86555 is still tracking the feature. |
This issue tracks the implementation of rust-lang/rfcs#2528, "type changing struct update syntax" (general tracking issue: #86555).
The text was updated successfully, but these errors were encountered: