-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #99835 - TaKO8Ki:suggest-adding-or-removing-ref-for-b…
…inding-pattern, r=estebank Suggest adding/removing `ref` for binding patterns This fixes what a fixme comment says. r? `@estebank`
- Loading branch information
Showing
8 changed files
with
160 additions
and
6 deletions.
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
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
21 changes: 21 additions & 0 deletions
21
src/test/ui/mismatched_types/suggest-adding-or-removing-ref-for-binding-pattern.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,21 @@ | ||
// run-rustfix | ||
#![allow(dead_code, unused_variables)] | ||
|
||
fn main() { | ||
enum Blah { | ||
A(isize, isize, usize), | ||
B(isize, usize), | ||
} | ||
|
||
match Blah::A(1, 1, 2) { | ||
Blah::A(_, x, ref y) | Blah::B(x, ref y) => {} | ||
//~^ ERROR mismatched types | ||
//~| ERROR variable `y` is bound inconsistently across alternatives separated by `|` | ||
} | ||
|
||
match Blah::A(1, 1, 2) { | ||
Blah::A(_, x, y) | Blah::B(x, y) => {} | ||
//~^ ERROR mismatched types | ||
//~| variable `y` is bound inconsistently across alternatives separated by `|` | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/ui/mismatched_types/suggest-adding-or-removing-ref-for-binding-pattern.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,21 @@ | ||
// run-rustfix | ||
#![allow(dead_code, unused_variables)] | ||
|
||
fn main() { | ||
enum Blah { | ||
A(isize, isize, usize), | ||
B(isize, usize), | ||
} | ||
|
||
match Blah::A(1, 1, 2) { | ||
Blah::A(_, x, ref y) | Blah::B(x, y) => {} | ||
//~^ ERROR mismatched types | ||
//~| ERROR variable `y` is bound inconsistently across alternatives separated by `|` | ||
} | ||
|
||
match Blah::A(1, 1, 2) { | ||
Blah::A(_, x, y) | Blah::B(x, ref y) => {} | ||
//~^ ERROR mismatched types | ||
//~| variable `y` is bound inconsistently across alternatives separated by `|` | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/test/ui/mismatched_types/suggest-adding-or-removing-ref-for-binding-pattern.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,49 @@ | ||
error[E0409]: variable `y` is bound inconsistently across alternatives separated by `|` | ||
--> $DIR/suggest-adding-or-removing-ref-for-binding-pattern.rs:11:43 | ||
| | ||
LL | Blah::A(_, x, ref y) | Blah::B(x, y) => {} | ||
| - first binding ^ bound in different ways | ||
|
||
error[E0409]: variable `y` is bound inconsistently across alternatives separated by `|` | ||
--> $DIR/suggest-adding-or-removing-ref-for-binding-pattern.rs:17:43 | ||
| | ||
LL | Blah::A(_, x, y) | Blah::B(x, ref y) => {} | ||
| - first binding ^ bound in different ways | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/suggest-adding-or-removing-ref-for-binding-pattern.rs:11:43 | ||
| | ||
LL | match Blah::A(1, 1, 2) { | ||
| ---------------- this expression has type `Blah` | ||
LL | Blah::A(_, x, ref y) | Blah::B(x, y) => {} | ||
| ----- ^ expected `&usize`, found `usize` | ||
| | | ||
| first introduced with type `&usize` here | ||
| | ||
= note: in the same arm, a binding must have the same type in all alternatives | ||
help: consider adding `ref` | ||
| | ||
LL | Blah::A(_, x, ref y) | Blah::B(x, ref y) => {} | ||
| +++ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/suggest-adding-or-removing-ref-for-binding-pattern.rs:17:39 | ||
| | ||
LL | match Blah::A(1, 1, 2) { | ||
| ---------------- this expression has type `Blah` | ||
LL | Blah::A(_, x, y) | Blah::B(x, ref y) => {} | ||
| - ^^^^^ expected `usize`, found `&usize` | ||
| | | ||
| first introduced with type `usize` here | ||
| | ||
= note: in the same arm, a binding must have the same type in all alternatives | ||
help: consider removing `ref` | ||
| | ||
LL - Blah::A(_, x, y) | Blah::B(x, ref y) => {} | ||
LL + Blah::A(_, x, y) | Blah::B(x, y) => {} | ||
| | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
Some errors have detailed explanations: E0308, E0409. | ||
For more information about an error, try `rustc --explain E0308`. |
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
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
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