-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Suggest adding/removing ref
for binding patterns
#99835
Merged
bors
merged 1 commit into
rust-lang:master
from
TaKO8Ki:suggest-adding-or-removing-ref-for-binding-pattern
Aug 5, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid this kind of span building when possible.