Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upFix handling of empty types in patterns. #38069
Conversation
rust-highfive
assigned
nikomatsakis
Nov 29, 2016
This comment has been minimized.
This comment has been minimized.
|
(rust_highfive has picked a reviewer for you, use r? to override) |
canndrew
changed the title
Fix handling of empty types in patterns.
[WIP] Fix handling of empty types in patterns.
Nov 29, 2016
ranma42
reviewed
Nov 29, 2016
| ConstructWitness => UsefulWithWitness(vec![Witness(vec![])]), | ||
| LeaveOutWitness => Useful, | ||
| } | ||
| } |
This comment has been minimized.
This comment has been minimized.
oli-obk
reviewed
Nov 29, 2016
| @@ -28,7 +28,7 @@ For example, the following `match` block has too many arms: | |||
| ```compile_fail,E0001 | |||
| match Some(0) { | |||
| Some(bar) => {/* ... */} | |||
| None => {/* ... */} | |||
| x => {/* ... */} // This handles the `None` case | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
oli-obk
Nov 29, 2016
Contributor
ah nevermind, because this triggers for E0001 and not for unreachable_patterns
This comment has been minimized.
This comment has been minimized.
|
cc @brson because this would be a new (insta-stable?) feature |
nikomatsakis
reviewed
Nov 30, 2016
| "unreachable pattern"); | ||
| err.span_label(pat.span, &"this is an unreachable pattern"); | ||
| // if we had a catchall pattern, hint at that | ||
| // if we had a catchall pattern, raise an error. |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Nov 30, 2016
Contributor
Why do we keep this as an error even if there is an _ pattern? Is there a strong reason?
This comment has been minimized.
This comment has been minimized.
canndrew
Dec 1, 2016
Author
Contributor
Not sure, it was @eddyb's suggestion. If that becomes a lint then we don't get to use E0001 at all though.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
eddyb
Dec 11, 2016
Member
The annoying thing is that a lint loses the help message, but if everyone else is fine with it, then sure, you can remove this special case.
This comment has been minimized.
This comment has been minimized.
|
Seems like we need some more test -- for example, I don't see any tests covering the private field cases, nor the "don't need to match variants" code, right? (is that because this is a WIP?) |
canndrew
force-pushed the
canndrew:empty-sub-patterns-again
branch
from
603dff6
to
e885c88
Dec 1, 2016
This comment has been minimized.
This comment has been minimized.
Yep, it should all be there now though. |
canndrew
changed the title
[WIP] Fix handling of empty types in patterns.
Fix handling of empty types in patterns.
Dec 1, 2016
This comment has been minimized.
This comment has been minimized.
|
It might be worth @arielb1 having a look at this too, seeing as they wrote the match checking code that I've fiddled with. |
canndrew
referenced this pull request
Dec 1, 2016
Closed
Check for uninhabited types in sub-patterns (#12609) #36476
This comment has been minimized.
This comment has been minimized.
|
So a quick summary of these changes: (Most) unreachable patterns now generate warnings instead of errors. I've added a new Unreachable patterns that used to sneak past the pattern-match checks no longer produce an I've fixed
Removed the special-casing that made Correct type information is carried on dummy wildcard patterns. This was necessary to make the above change but I suspect it's also a more general bugfix. It used to be possible for the pattern-match algs to be handling a dummy
|
This comment has been minimized.
This comment has been minimized.
|
|
canndrew
force-pushed the
canndrew:empty-sub-patterns-again
branch
from
8a09338
to
b9e51f9
Dec 3, 2016
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis this is ready now btw. @brson any chance I could get a crater run on this? |
This comment has been minimized.
This comment has been minimized.
|
@canndrew sorry for delay. Mozilla all hands didn't leave much time for reviewing. I'm going to be on vacation next week but will try to find time, else perhaps someone else can/should review. |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis That's alright. I was just a bit angsty that this would get ignored for a month or so and eventually bit-rot like the last PR for this did. I understand you guys have a very full plate though. Probably @arielb1 would be the best person to review this? |
arielb1
reviewed
Dec 10, 2016
| @@ -20,7 +20,7 @@ fn tail(source_list: &IntList) -> IntList { | |||
| match source_list { | |||
| &IntList::Cons(val, box ref next_list) => tail(next_list), | |||
| &IntList::Cons(val, box Nil) => IntList::Cons(val, box Nil), | |||
| //~^ ERROR unreachable pattern | |||
| //~^ ERROR cannot move out of borrowed content | |||
This comment has been minimized.
This comment has been minimized.
arielb1
reviewed
Dec 10, 2016
| ty::TyAdt(def, substs) if def.is_enum() && def.variants.len() != 1 => { | ||
| def.variants.iter().filter_map(|v| { | ||
| let mut visited = FxHashSet::default(); | ||
| if v.is_uninhabited_recurse(&mut visited, |
This comment has been minimized.
This comment has been minimized.
arielb1
Dec 10, 2016
Contributor
I'm worried that the recursion here might cause things to be slow. Could you try adding a cache somewhere?
This comment has been minimized.
This comment has been minimized.
|
I've refactored
Then |
This comment has been minimized.
This comment has been minimized.
|
Anyone know what happened to travis there? |
This comment has been minimized.
This comment has been minimized.
|
@canndrew I think Travis has been busted for almost a week now. |
This comment has been minimized.
This comment has been minimized.
|
Is there anything more I can do to help get this reviewed? |
This comment has been minimized.
This comment has been minimized.
|
@canndrew back now, sorry about that. |
This comment has been minimized.
This comment has been minimized.
|
Will review. |
This comment has been minimized.
This comment has been minimized.
|
Sorry for delay. I am doing a bit of reading up on the general algorithm since I'm feeling ill-equipped to judge this patch. =) |
This comment has been minimized.
This comment has been minimized.
|
That's cool.
Algorithm-wise these should be the only relevant changes and should be enough to make it correctly handle empty types. |
canndrew
referenced this pull request
Dec 25, 2016
Open
Tracking issue for TryFrom/TryInto traits #33417
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Jan 5, 2017
This comment has been minimized.
This comment has been minimized.
|
@bors r=nikomatsakis force |
This comment has been minimized.
This comment has been minimized.
|
@bors retry |
This comment has been minimized.
This comment has been minimized.
|
@bors r=nikomatsakis |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Jan 6, 2017
This comment has been minimized.
This comment has been minimized.
|
|
bors
merged commit 275c19d
into
rust-lang:master
Jan 6, 2017
bors
referenced this pull request
Jan 6, 2017
Merged
[11/n] Separate ty::Tables into one per each body. #38813
glaebhoerl
referenced this pull request
Jan 6, 2017
Closed
Precise range exhaustiveness check for match on integer patterns #1550
This was referenced Jan 6, 2017
arielb1
referenced this pull request
Jan 11, 2017
Closed
Unreachable expression in void-1.0.2, Rust 1.16 #38975
This comment has been minimized.
This comment has been minimized.
|
I suggest a |
GuillaumeGomez
added
the
relnotes
label
Jan 11, 2017
This comment has been minimized.
This comment has been minimized.
|
Done. |
canndrew commentedNov 29, 2016
Fix for #12609.