Skip to content
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

Set label for unreachable pattern #35297

Merged
merged 2 commits into from
Aug 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/librustc_const_eval/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ fn check_arms(cx: &MatchCheckCtxt,
hir::MatchSource::Normal => {
let mut err = struct_span_err!(cx.tcx.sess, pat.span, E0001,
"unreachable pattern");
err.span_label(pat.span, &format!("this is an unreachable pattern"));
// if we had a catchall pattern, hint at that
for row in &seen.0 {
if pat_is_catchall(&cx.tcx.def_map.borrow(), row[0].0) {
Expand Down
4 changes: 4 additions & 0 deletions src/test/compile-fail/issue-31221.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ fn main() {
//~^ NOTE this pattern matches any value
Var2 => (),
//~^ ERROR unreachable pattern
//~^^ NOTE this is an unreachable pattern
};
match &s {
&Var1 => (),
&Var3 => (),
//~^ NOTE this pattern matches any value
&Var2 => (),
//~^ ERROR unreachable pattern
//~^^ NOTE this is an unreachable pattern
};
let t = (Var1, Var1);
match t {
Expand All @@ -37,6 +39,7 @@ fn main() {
//~^ NOTE this pattern matches any value
anything => ()
//~^ ERROR unreachable pattern
//~^^ NOTE this is an unreachable pattern
};
// `_` need not emit a note, it is pretty obvious already.
let t = (Var1, Var1);
Expand All @@ -45,5 +48,6 @@ fn main() {
_ => (),
anything => ()
//~^ ERROR unreachable pattern
//~^^ NOTE this is an unreachable pattern
};
}