-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 destructuring_assignment
#71126
Comments
We've opened an RFC for destructuring assignment: rust-lang/rfcs#2909. |
destructuring_assignment
destructuring_assignment
…enkov Implement destructuring assignment for tuples This is the first step towards implementing destructuring assignment (RFC: rust-lang/rfcs#2909, tracking issue: rust-lang#71126). This PR is the first part of rust-lang#71156, which was split up to allow for easier review. Quick summary: This change allows destructuring the LHS of an assignment if it's a (possibly nested) tuple. It is implemented via a desugaring (AST -> HIR lowering) as follows: ```rust (a,b) = (1,2) ``` ... becomes ... ```rust { let (lhs0,lhs1) = (1,2); a = lhs0; b = lhs1; } ``` Thanks to `@varkor` who helped with the implementation, particularly around default binding modes. r? `@petrochenkov`
…ing, r=petrochenkov Implement destructuring assignment for structs and slices This is the second step towards implementing destructuring assignment (RFC: rust-lang/rfcs#2909, tracking issue: rust-lang#71126). This PR is the second part of rust-lang#71156, which was split up to allow for easier review. Note that the first PR (rust-lang#78748) is not merged yet, so it is included as the first commit in this one. I thought this would allow the review to start earlier because I have some time this weekend to respond to reviews. If `@petrochenkov` prefers to wait until the first PR is merged, I totally understand, of course. This PR implements destructuring assignment for (tuple) structs and slices. In order to do this, the following *parser change* was necessary: struct expressions are not required to have a base expression, i.e. `Struct { a: 1, .. }` becomes legal (in order to act like a struct pattern). Unfortunately, this PR slightly regresses the diagnostics implemented in rust-lang#77283. However, it is only a missing help message in `src/test/ui/issues/issue-77218.rs`. Other instances of this diagnostic are not affected. Since I don't exactly understand how this help message works and how to fix it yet, I was hoping it's OK to regress this temporarily and fix it in a follow-up PR. Thanks to `@varkor` who helped with the implementation, particularly around the struct rest changes. r? `@petrochenkov`
…ing, r=petrochenkov Implement destructuring assignment for structs and slices This is the second step towards implementing destructuring assignment (RFC: rust-lang/rfcs#2909, tracking issue: rust-lang#71126). This PR is the second part of rust-lang#71156, which was split up to allow for easier review. Note that the first PR (rust-lang#78748) is not merged yet, so it is included as the first commit in this one. I thought this would allow the review to start earlier because I have some time this weekend to respond to reviews. If ``@petrochenkov`` prefers to wait until the first PR is merged, I totally understand, of course. This PR implements destructuring assignment for (tuple) structs and slices. In order to do this, the following *parser change* was necessary: struct expressions are not required to have a base expression, i.e. `Struct { a: 1, .. }` becomes legal (in order to act like a struct pattern). Unfortunately, this PR slightly regresses the diagnostics implemented in rust-lang#77283. However, it is only a missing help message in `src/test/ui/issues/issue-77218.rs`. Other instances of this diagnostic are not affected. Since I don't exactly understand how this help message works and how to fix it yet, I was hoping it's OK to regress this temporarily and fix it in a follow-up PR. Thanks to ``@varkor`` who helped with the implementation, particularly around the struct rest changes. r? ``@petrochenkov``
…ing, r=petrochenkov Implement destructuring assignment for structs and slices This is the second step towards implementing destructuring assignment (RFC: rust-lang/rfcs#2909, tracking issue: rust-lang#71126). This PR is the second part of rust-lang#71156, which was split up to allow for easier review. Note that the first PR (rust-lang#78748) is not merged yet, so it is included as the first commit in this one. I thought this would allow the review to start earlier because I have some time this weekend to respond to reviews. If ``@petrochenkov`` prefers to wait until the first PR is merged, I totally understand, of course. This PR implements destructuring assignment for (tuple) structs and slices. In order to do this, the following *parser change* was necessary: struct expressions are not required to have a base expression, i.e. `Struct { a: 1, .. }` becomes legal (in order to act like a struct pattern). Unfortunately, this PR slightly regresses the diagnostics implemented in rust-lang#77283. However, it is only a missing help message in `src/test/ui/issues/issue-77218.rs`. Other instances of this diagnostic are not affected. Since I don't exactly understand how this help message works and how to fix it yet, I was hoping it's OK to regress this temporarily and fix it in a follow-up PR. Thanks to ``@varkor`` who helped with the implementation, particularly around the struct rest changes. r? ``@petrochenkov``
…etrochenkov Make `_` an expression, to discard values in destructuring assignments This is the third and final step towards implementing destructuring assignment (RFC: rust-lang/rfcs#2909, tracking issue: rust-lang#71126). This PR is the third and final part of rust-lang#71156, which was split up to allow for easier review. With this PR, an underscore `_` is parsed as an expression but is allowed *only* on the left-hand side of a destructuring assignment. There it simply discards a value, similarly to the wildcard `_` in patterns. For instance, ```rust (a, _) = (1, 2) ``` will simply assign 1 to `a` and discard the 2. Note that for consistency, ``` _ = foo ``` is also allowed and equivalent to just `foo`. Thanks to ````@varkor```` who helped with the implementation, particularly around pre-expansion gating. r? ````@petrochenkov````
I got kind of a weird error message recently that probably isn't too concerning, but maybe someone more familiar with the implementation of the The following extremely weird program: fn main() {
let y = Some(42);
if y < Some(_) {}
} Errors with:
I'm wondering whether it's considered a problem that the compiler appears to consider |
@bstrie Thanks for reporting this. The error message is indeed a bit misleading.
In fact, the compiler does not consider this I didn't think this was a big problem because as soon as destructuring assignments are stabilized, you'll just get the second error message ( |
I think this is ok -- the older one wasn't particularly amazing:
That said, it might be nice to tune the error based on whether there's a |
No, I was just surprised and wanted to make sure this wasn't indicative of some deeper bug. :) Ship it! |
Hey everyone. I'm relatively new so I might be missing something, but I can't see what is the roadmap for this feature. Is this expected to release in the next version of Rust? |
The next step is for someone on the lang team to propose a final comment period, after which the feature can be stabilized. I'll bring it up with the lang team on Zulip. |
@bstrie This needs a stabilization report. |
Hello @bstrie, are there any news on the stabilization, by any chance? :) |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
@rfcbot reviewed I'm excited about this :) |
Now that the final comment period has ended, anyone can open up a stabilisation PR. The process is very straightforward, and essentially involves removing the |
I'll take a shot at a stabilization PR. |
PR is up: #90521 |
Something related in C# 10: |
…ignment, r=jackh726,pnkfelix Stabilize `destructuring_assignment` Closes rust-lang#71126 - [Stabilization report](rust-lang#71126 (comment)) - [Completed FCP](rust-lang#71126 (comment)) `@rustbot` label +F-destructuring-assignment +T-lang Also needs +relnotes but I don't have permission to add that tag.
…r=jackh726,pnkfelix Stabilize `destructuring_assignment` Closes #71126 - [Stabilization report](rust-lang/rust#71126 (comment)) - [Completed FCP](rust-lang/rust#71126 (comment)) `@rustbot` label +F-destructuring-assignment +T-lang Also needs +relnotes but I don't have permission to add that tag.
The usage of the `destrucuring_assignment` feature was added just for fun, it only saves two lines of code. The feature is soon stable, see rust-lang/rust#71126.
The 'destructuring_assignment' to tuples [1] was not stable with rust toolchina 1.56. [1] rust-lang/rust#71126 Signed-off-by: Bo Chen <chen.bo@intel.com>
This is a tracking issue for the RFC "Destructuring assignment" (rust-lang/rfcs#2909).
The feature gate for the issue is
#![feature(destructuring_assignment)]
.About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also uses 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.
Steps
_
expressions (Make_
an expression, to discard values in destructuring assignments #79016)destructuring_assignment
#90521)Implementation history
The initial implementation was carried out in three steps by @fanzier (split out from an initial implementation, #71156):
_
expressions: Make_
an expression, to discard values in destructuring assignments #79016The text was updated successfully, but these errors were encountered: