-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Expand potential inner Or
pattern for THIR
#98200
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#[allow(unused_variables)] | ||
#[allow(unused_parens)] | ||
fn main() { | ||
let x = "foo"; | ||
match x { | ||
x @ ((("h" | "ho" | "yo" | ("dude" | "w")) | () | "nop") | ("hey" | "gg")) | | ||
//~^ ERROR mismatched types | ||
x @ ("black" | "pink") | | ||
x @ ("red" | "blue") => { | ||
} | ||
_ => (), | ||
} | ||
} |
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 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/inner-or-pat-2.rs:6:54 | ||
| | ||
LL | match x { | ||
| - this expression has type `&str` | ||
LL | x @ ((("h" | "ho" | "yo" | ("dude" | "w")) | () | "nop") | ("hey" | "gg")) | | ||
| ^^ expected `str`, found `()` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// run-pass | ||
|
||
#[allow(unreachable_patterns)] | ||
#[allow(unused_variables)] | ||
#[allow(unused_parens)] | ||
fn main() { | ||
let x = "foo"; | ||
|
||
match x { | ||
x @ ("foo" | "bar") | | ||
(x @ "red" | (x @ "blue" | x @ "red")) => { | ||
} | ||
_ => (), | ||
} | ||
} |
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,13 @@ | ||
#[allow(unused_variables)] | ||
#[allow(unused_parens)] | ||
fn main() { | ||
let x = "foo"; | ||
|
||
match x { | ||
x @ ("foo" | "bar") | | ||
(x @ "red" | (x @ "blue" | "red")) => { | ||
//~^ variable `x` is not bound in all patterns | ||
} | ||
_ => (), | ||
} | ||
} |
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 @@ | ||
error[E0408]: variable `x` is not bound in all patterns | ||
--> $DIR/inner-or-pat-4.rs:8:37 | ||
| | ||
LL | (x @ "red" | (x @ "blue" | "red")) => { | ||
| - ^^^^^ pattern doesn't bind `x` | ||
| | | ||
| variable not in all patterns | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0408`. |
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,14 @@ | ||
// run-pass | ||
|
||
#[allow(unused_variables)] | ||
#[allow(unused_parens)] | ||
fn main() { | ||
let x = "foo"; | ||
match x { | ||
x @ ((("h" | "ho" | "yo" | ("dude" | "w")) | "no" | "nop") | ("hey" | "gg")) | | ||
x @ ("black" | "pink") | | ||
x @ ("red" | "blue") => { | ||
} | ||
_ => (), | ||
} | ||
} |
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.
Is it possible to make
expand_or_pat
recursively expand or patterns instead?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.
I couldn't make that one recursive but made a new function that is recursive.
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.
Either the other use of expand_or_Pat is dead code now or it's still got that issue. Check whether it's dead by panicking inside of it instead of doing any logic
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.
It can't be dead code because line 835, it's the only reason I couldn't replace the function altogether
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.
That call may be dead after your change is what I'm thinking. Since you now expand all the nested
Or
patterns, line 835 may not encounterOr
patterns anymore.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.
I did as you said, it panicked. Newly added function is only called via
fn push
and that is called via line 846.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.
I don't like that we now have one function that does the recursive work and one that doesn't. On what kind of matches did it panic? Should we call the new function at that site to reduce duplication and make it more general?
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.
The other function just works like iterator right now, I tried to merge these two functions together but problem is, it's quite tricky because of line 838 if I remove
expand_or_pat
altogether and just callexpand_and_extend
compiler gives a warningunreachable pattern
even though both of them should do the same thing at this point.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.
that is suspicious indeed and makes me confident that we should definitely make them work the same and figure out why they are problematic
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.
I think I understand now why the compiler gives "unreachable pattern" err, to reach those places I need to access
is_under_guard
for each recursive call, but also push to the matrix has to happen after the callis_useful
to triggerif v.is_empty()
where the matrix has to be empty. Even if I throw all those out of the window I need to callis_useful
for eachv
🤷♂️