Skip to content

Commit 061a223

Browse files
committed
auto merge of #5118 : youknowone/rust/match-guard, r=nikomatsakis
Fix ICE while there is no remained arms after checking guards. This fix #3601 also.
2 parents 8e492cc + b79c4dc commit 061a223

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/librustc/middle/check_match.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ pub fn check_expr(cx: @MatchCheckCtxt, ex: @expr, &&s: (), v: visit::vt<()>) {
101101
_ => { /* We assume only enum types can be uninhabited */ }
102102
}
103103
let arms = vec::concat(arms.filter_mapped(unguarded_pat));
104-
check_exhaustive(cx, ex.span, arms);
104+
if arms.is_empty() {
105+
cx.tcx.sess.span_err(ex.span, ~"non-exhaustive patterns");
106+
} else {
107+
check_exhaustive(cx, ex.span, arms);
108+
}
105109
}
106110
_ => ()
107111
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
match 0 { 1 => () } //~ ERROR non-exhaustive patterns
13+
match 0 { 0 if false => () } //~ ERROR non-exhaustive patterns
14+
}

0 commit comments

Comments
 (0)