Skip to content

Commit 40d3241

Browse files
committedMay 21, 2014
rustc: Avoid out of bounds in check_match
Closes #12116
1 parent 1b2dd90 commit 40d3241

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
 

‎src/librustc/middle/check_match.rs

+1
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@Pat]) -> useful {
247247
_ => *r.get(0)
248248
}
249249
}
250+
None if v.len() == 0 => return not_useful,
250251
None => v[0]
251252
};
252253
let left_ty = if real_pat.id == 0 { ty::mk_nil() }

‎src/test/compile-fail/issue-12116.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2012-2014 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+
enum IntList {
12+
Cons(int, Box<IntList>),
13+
Nil
14+
}
15+
16+
fn tail(source_list: &IntList) -> IntList {
17+
match source_list {
18+
&Cons(val, box ref next_list) => tail(next_list),
19+
&Cons(val, box Nil) => Cons(val, box Nil),
20+
//~^ ERROR: unreachable pattern
21+
_ => fail!()
22+
}
23+
}
24+
25+
fn main() {}

0 commit comments

Comments
 (0)
Please sign in to comment.