-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Account for
ref
and mut
in the wrong place for pattern ident rena…
…ming If the user writes `S { ref field: name }` instead of `S { field: ref name }`, we suggest the correct code. Fix #72298.
- Loading branch information
Showing
4 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
tests/ui/pattern/incorrect-placement-of-pattern-modifiers.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// run-rustfix | ||
struct S { | ||
field_name: (), | ||
} | ||
|
||
fn main() { | ||
match (S {field_name: ()}) { | ||
S {field_name: ref _foo} => {} //~ ERROR expected `,` | ||
} | ||
let _: usize = 3usize; //~ ERROR mismatched types | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/ui/pattern/incorrect-placement-of-pattern-modifiers.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// run-rustfix | ||
struct S { | ||
field_name: (), | ||
} | ||
|
||
fn main() { | ||
match (S {field_name: ()}) { | ||
S {ref field_name: _foo} => {} //~ ERROR expected `,` | ||
} | ||
let _: usize = 3u8; //~ ERROR mismatched types | ||
} |
30 changes: 30 additions & 0 deletions
30
tests/ui/pattern/incorrect-placement-of-pattern-modifiers.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
error: expected `,` | ||
--> $DIR/incorrect-placement-of-pattern-modifiers.rs:8:26 | ||
| | ||
LL | S {ref field_name: _foo} => {} | ||
| - ^ | ||
| | | ||
| while parsing the fields for this pattern | ||
| | ||
help: the pattern modifiers belong after the `:` | ||
| | ||
LL - S {ref field_name: _foo} => {} | ||
LL + S {field_name: ref _foo} => {} | ||
| | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/incorrect-placement-of-pattern-modifiers.rs:10:20 | ||
| | ||
LL | let _: usize = 3u8; | ||
| ----- ^^^ expected `usize`, found `u8` | ||
| | | ||
| expected due to this | ||
| | ||
help: change the type of the numeric literal from `u8` to `usize` | ||
| | ||
LL | let _: usize = 3usize; | ||
| ~~~~~ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |