You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Custom diagnostic for bad mut in pattern with sub-bindings #63764
error: expected one of `:`, `;`, `=`, or `@`, found `{`
--> src/main.rs:3:17
|
3 | let mut Foo { x: x } = Foo { x: 3 };
| ^ expected one of `:`, `;`, `=`, or `@` here
It should instead parse as if it were let Foo { x: mut x } = Foo { x: 3 }; (medium priority), silence any complaints that mut is unnecessary (lower priority) and emit a custom error explaining that mut cannot lead a pattern with subpatterns (must have), and suggest the appropriate mut placement in the sub-bindings (nice to have):
error: incorrect `mut` pattern
--> src/main.rs:3:17
|
3 | let mut Foo { x: x } = Foo { x: 3 };
| ^^^ patterns with sub-bindings can't be marked as `mut`
help: mark the individual sub-bindings as `mut` instead
3 | let Foo { x: mut x } = Foo { x: 3 };
| -- ^^^
or where it is called. If a ref token does not follow you simply call the recursive pattern parser and then once you have parsed a PatKind you walk (with a mutating visitor) to all the binding sites, insert a mut there, pretty print it and suggest the output.
Activity
Centril commentedon Aug 20, 2019
This should be relatively easy to do by hooking into
rust/src/libsyntax/parse/parser/pat.rs
Line 289 in bea0372
reftoken does not follow you simply call the recursive pattern parser and then once you have parsed aPatKindyou walk (with a mutating visitor) to all the binding sites, insert amutthere, pretty print it and suggest the output.Centril commentedon Aug 20, 2019
Marking as blocked for now on #63693 so we don't get a lot of conflicts.
Rollup merge of rust-lang#63945 - Centril:recover-mut-pat, r=estebank