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 upChange unreachable pattern ICEs to warnings #39127
Conversation
rust-highfive
assigned
arielb1
Jan 17, 2017
This comment has been minimized.
This comment has been minimized.
|
r? @arielb1 (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
Ugh, bloody make tidy. Every single time. |
This comment has been minimized.
This comment has been minimized.
|
So to summarise: An unreachable pattern in a |
This comment has been minimized.
This comment has been minimized.
nikomatsakis
approved these changes
Jan 17, 2017
nikomatsakis
reviewed
Jan 17, 2017
| @@ -1833,8 +1835,12 @@ impl<'a> LoweringContext<'a> { | |||
| ExprKind::Try(ref sub_expr) => { | |||
| // to: | |||
| // | |||
| // #[allow(unreachable_patterns)] | |||
This comment has been minimized.
This comment has been minimized.
nikomatsakis
Jan 17, 2017
Contributor
Hmm, so, this #[allow(unreachable_patterns)] annotation presumably affects the <expr>, right? That seems unfortunate. i.e., if I do (match { ... })?, do we still see warnings from the inner match?
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.
canndrew
Jan 18, 2017
Author
Contributor
I still seem to get warnings without these. At least the unreachable_code attribute seems to have an effect. I was thinking I'll change the code to this:
match Carrier::translate(<expr>) {
#[allow(unused)]
Ok(val) => val,
#[allow(unused)]
Err(err) => return Carrier::from_error(From::from(err)),
}
This comment has been minimized.
This comment has been minimized.
arielb1
Jan 18, 2017
Contributor
The unreachable_code attribute is indeed fine - no user-defined code exists under it. It's the unreachable_patterns attribute that is the problem - could you check why is it needed?
This comment has been minimized.
This comment has been minimized.
|
r? @nikomatsakis (I'm assuming @arielb1 doesn't have time) |
rust-highfive
assigned
nikomatsakis
and unassigned
arielb1
Jan 17, 2017
This comment has been minimized.
This comment has been minimized.
|
Wait, do expr-level |
This comment has been minimized.
This comment has been minimized.
|
I do have time. |
nikomatsakis
assigned
arielb1
Jan 19, 2017
This comment has been minimized.
This comment has been minimized.
|
@arielb1 ok :) either way. In any case, I think we both agree that we should try to avoid having warnings get squelched in user code somehow. I agree with the suggestion of using the |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
The PR is required. #39151 just gates the uninhabitableness of references, it does not revert the changes for matching |
arielb1
reviewed
Jan 19, 2017
| val_ident, | ||
| val_pat.id, | ||
| attrs)); | ||
| let val_block = P(self.block_expr(val_expr)); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
canndrew
added some commits
Jan 20, 2017
This comment has been minimized.
This comment has been minimized.
|
Sorry for spamming travis. I've now changed the try desugaring to this: match Carrier::translate(<expr>) {
Ok(val) => #[allow(unreachable_code)] val,
Err(err) => #[allow(unreachable_code)] return Carrier::from_error(From::from(err)),
}That seems to be all we need to crush the warnings. |
arielb1
reviewed
Jan 20, 2017
| // Ok(val) => { | ||
| // #[allow(unreachable_code)] | ||
| // val | ||
| // } | ||
| // Err(err) => return Carrier::from_error(From::from(err)) |
This comment has been minimized.
This comment has been minimized.
arielb1
Jan 20, 2017
•
Contributor
nit: update the comment here (including the absence of BlockExpr/ExprBlock pair.
arielb1
reviewed
Jan 20, 2017
| let val_expr = P(self.expr_ident_with_attrs(e.span, | ||
| val_ident, | ||
| val_pat.id, | ||
| From::from(attrs.clone()))); |
This comment has been minimized.
This comment has been minimized.
arielb1
reviewed
Jan 20, 2017
| hir::MatchSource::TryDesugar => { | ||
| span_bug!(pat.span, "unreachable try pattern") | ||
| }, | ||
| hir::MatchSource::TryDesugar => {} |
This comment has been minimized.
This comment has been minimized.
arielb1
Jan 20, 2017
•
Contributor
A comment would be nice, for example:
// unreachable patterns in a try expression occur when one of the Result
// variants is uninhabited, and should cause a warning.
arielb1
requested changes
Jan 20, 2017
|
nice modulo comment nits. |
canndrew
added some commits
Jan 21, 2017
This comment has been minimized.
This comment has been minimized.
|
@bors r+ |
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 22, 2017
This comment has been minimized.
This comment has been minimized.
|
|
canndrew commentedJan 17, 2017
Allow code with unreachable
?andforpatterns to compile.Add some tests.