Skip to content

Commit

Permalink
Rollup merge of rust-lang#35297 - saml:e0001-label, r=jonathandturner
Browse files Browse the repository at this point in the history
Set label for unreachable pattern

Part of rust-lang#35233
Fixes rust-lang#35190

r? @jonathandturner
  • Loading branch information
GuillaumeGomez authored Aug 5, 2016
2 parents fa149c3 + 034e659 commit 4b170d5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
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
};
}

0 comments on commit 4b170d5

Please sign in to comment.