Skip to content

Commit

Permalink
Add non-exhaustive check for match guards
Browse files Browse the repository at this point in the history
Fix ICE while there is no remained arms after checking guards
  • Loading branch information
youknowone committed Feb 26, 2013
1 parent 6439e28 commit b79c4dc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/librustc/middle/check_match.rs
Expand Up @@ -101,7 +101,11 @@ pub fn check_expr(cx: @MatchCheckCtxt, ex: @expr, &&s: (), v: visit::vt<()>) {
_ => { /* We assume only enum types can be uninhabited */ }
}
let arms = vec::concat(arms.filter_mapped(unguarded_pat));
check_exhaustive(cx, ex.span, arms);
if arms.is_empty() {
cx.tcx.sess.span_err(ex.span, ~"non-exhaustive patterns");
} else {
check_exhaustive(cx, ex.span, arms);
}
}
_ => ()
}
Expand Down
14 changes: 14 additions & 0 deletions src/test/compile-fail/match-non-exhaustive.rs
@@ -0,0 +1,14 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() {
match 0 { 1 => () } //~ ERROR non-exhaustive patterns
match 0 { 0 if false => () } //~ ERROR non-exhaustive patterns
}

5 comments on commit b79c4dc

@bors
Copy link
Contributor

@bors bors commented on b79c4dc Feb 27, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from nikomatsakis
at youknowone@b79c4dc

@bors
Copy link
Contributor

@bors bors commented on b79c4dc Feb 27, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging youknowone/rust/match-guard = b79c4dc into auto

@bors
Copy link
Contributor

@bors bors commented on b79c4dc Feb 27, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

youknowone/rust/match-guard = b79c4dc merged ok, testing candidate = 061a223

@bors
Copy link
Contributor

@bors bors commented on b79c4dc Feb 27, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on b79c4dc Feb 27, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = 061a223

Please sign in to comment.