Match ergonomics 2024: implement mutable by-reference bindings#123080
Match ergonomics 2024: implement mutable by-reference bindings#123080bors merged 3 commits intorust-lang:masterfrom
Conversation
|
Some changes occurred in match checking cc @Nadrieril Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt Some changes occurred in match lowering cc @Nadrieril |
|
From a process perspective, we don't have an accepted RFC for this so I think we need a lang team liaison. Either that or write a precise proposal that can be approved (the original proposal was positively received but didn't get proposer "we agree to do this" kind of approval) |
Nadrieril
left a comment
There was a problem hiding this comment.
First of all, thanks for doing this work!
This PR is doing a bunch of different things at once; for future PRs I would have found it much easier to review a series of commits each doing a single change, e.g. the first commit would have changed how ByRef/BindingAnnotation work, a second one would have removed BindingMode etc and the last one would have added the new mut ref mut/mut ref possibility.
No need to change that now though, I've read through it. I like what you did with BindingAnnotation; this looks good. r=me once the feature gate is marked "incomplete" and we get a liaison.
| | - | ||
| | | | ||
| | first assignment to `a` | ||
| | help: consider making this binding mutable: `mut a` |
There was a problem hiding this comment.
it would be nice to extend this help message to suggest mut ref as well when the feature is active. I'lll let you decide whether to include in this PR or do it separately
There was a problem hiding this comment.
I'll do it separately, I'd rather the BindingAnnotation/ByRef changes land first so later PRs can make use of them
|
☔ The latest upstream changes (presumably #123121) made this pull request unmergeable. Please resolve the merge conflicts. |
fc0bc1d to
51de637
Compare
This comment has been minimized.
This comment has been minimized.
51de637 to
025bc0e
Compare
This comment has been minimized.
This comment has been minimized.
025bc0e to
2ab563f
Compare
2ab563f to
f219129
Compare
f219129 to
e931595
Compare
|
This should be ready to go, now that we have a liaison (#123076 (comment)). @rustbot label -S-waiting-on-team S-waiting-on-review |
|
Let's goooo @bors r+ |
…eril Match ergonomics 2024: implement mutable by-reference bindings Implements the mutable by-reference bindings portion of match ergonomics 2024 (rust-lang#123076), with the `mut ref`/`mut ref mut` syntax, under feature gate `mut_ref`. r? `@Nadrieril` `@rustbot` label A-patterns A-edition-2024
|
💔 Test failed - checks-actions |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
|
@bors retry |
|
☀️ Test successful - checks-actions |
|
Finished benchmarking commit (45796d1): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 668.769s -> 668.043s (-0.11%) |
|
I think this doesn't feature-gate Specifically, this code fails before this PR but compiles after (in all editions), with no unstable features enabled (playground). #![allow(unused)]
struct Foo {
x: i32,
}
fn main() {
let Foo { mut ref x } = Foo { x: 4 };
// let Foo { x: mut ref x } = Foo { x: 4 }; // this errors correctly
}before: error: expected identifier, found keyword `ref`
--> src/main.rs:6:19
|
8 | let Foo { mut ref x } = Foo { x: 4 };
| ^^^ expected identifier, found keyword
error: expected `,`
--> src/main.rs:6:23
|
8 | let Foo { mut ref x } = Foo { x: 4 };
| --- ^
| |
| while parsing the fields for this pattern
error: could not compile `bisect-when-mut-ref-patterns-were-added` (bin "bisect-when-mut-ref-patterns-were-added") due to 2 previous errorsafter: (no errors) I think this is missing a diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs
index 59e0cd92c4c..fd524462e76 100644
--- a/compiler/rustc_parse/src/parser/pat.rs
+++ b/compiler/rustc_parse/src/parser/pat.rs
@@ -1404,6 +1404,10 @@ fn parse_pat_field(&mut self, lo: Span, attrs: AttrVec) -> PResult<'a, PatField>
let fieldpat = self.mk_pat_ident(boxed_span.to(hi), ann, fieldname);
let subpat =
if is_box { self.mk_pat(lo.to(hi), PatKind::Box(fieldpat)) } else { fieldpat };
+ if matches!(subpat.kind, PatKind::Ident(BindingAnnotation(ByRef::Yes(_), Mutability::Mut), ..))
+ {
+ self.psess.gated_spans.gate(sym::mut_ref, subpat.span);
+ }
(subpat, fieldname, true)
}; |
|
Damn that's definitely not intentional! If you don't mind opening an issue or even a PR given that you already know how to fix it! |
…shorthand-gate, r=JonathanBrouwer Feature-gate `mut ref` patterns in struct pattern field shorthand Tracking issue for `mut_ref` (and other parts of Match Ergonomics 2024): rust-lang#123076 rust-lang#123080 introduced `mut ref`[^1] patterns (for by-reference bindings where the binding itself is mutable), feature-gated behind the `mut_ref` feature, except for in struct pattern shorthand, where the feature gating was missing. Thus, `mut ref` patterns in struct pattern shorthand has been unintentionally stable for ~18 months (since 1.79.0 ([compiler explorer](https://rust.godbolt.org/z/4WTrvhboT))). This PR adds feature-gating for `mut ref` patterns in struct pattern shorthand. Since this is reverting an accidental stabilization, this probably needs a crater run and a T-lang FCP? Some alternative possibilities: * Do nothing (let the inconsistency exist until `feature(mut_ref)` is stabilized) * Document the existing behavior * Do a FCW instead of fully feature-gating * Stabilize `feature(mut_ref)` CC rust-lang#123080 (comment) CC @Nadrieril [^1]: everything in this description also applies analogously to `mut ref mut` patterns.
…shorthand-gate, r=JonathanBrouwer Feature-gate `mut ref` patterns in struct pattern field shorthand Tracking issue for `mut_ref` (and other parts of Match Ergonomics 2024): rust-lang#123076 rust-lang#123080 introduced `mut ref`[^1] patterns (for by-reference bindings where the binding itself is mutable), feature-gated behind the `mut_ref` feature, except for in struct pattern shorthand, where the feature gating was missing. Thus, `mut ref` patterns in struct pattern shorthand has been unintentionally stable for ~18 months (since 1.79.0 ([compiler explorer](https://rust.godbolt.org/z/4WTrvhboT))). This PR adds feature-gating for `mut ref` patterns in struct pattern shorthand. Since this is reverting an accidental stabilization, this probably needs a crater run and a T-lang FCP? Some alternative possibilities: * Do nothing (let the inconsistency exist until `feature(mut_ref)` is stabilized) * Document the existing behavior * Do a FCW instead of fully feature-gating * Stabilize `feature(mut_ref)` CC rust-lang#123080 (comment) CC @Nadrieril [^1]: everything in this description also applies analogously to `mut ref mut` patterns.
Rollup merge of #151102 - zachs18:mut-ref-in-struct-pattern-shorthand-gate, r=JonathanBrouwer Feature-gate `mut ref` patterns in struct pattern field shorthand Tracking issue for `mut_ref` (and other parts of Match Ergonomics 2024): #123076 #123080 introduced `mut ref`[^1] patterns (for by-reference bindings where the binding itself is mutable), feature-gated behind the `mut_ref` feature, except for in struct pattern shorthand, where the feature gating was missing. Thus, `mut ref` patterns in struct pattern shorthand has been unintentionally stable for ~18 months (since 1.79.0 ([compiler explorer](https://rust.godbolt.org/z/4WTrvhboT))). This PR adds feature-gating for `mut ref` patterns in struct pattern shorthand. Since this is reverting an accidental stabilization, this probably needs a crater run and a T-lang FCP? Some alternative possibilities: * Do nothing (let the inconsistency exist until `feature(mut_ref)` is stabilized) * Document the existing behavior * Do a FCW instead of fully feature-gating * Stabilize `feature(mut_ref)` CC #123080 (comment) CC @Nadrieril [^1]: everything in this description also applies analogously to `mut ref mut` patterns.
Implements the mutable by-reference bindings portion of match ergonomics 2024 (#123076), with the
mut ref/mut ref mutsyntax, under feature gatemut_ref.r? @Nadrieril
@rustbot label A-patterns A-edition-2024