Closes #8391
This commit is contained in:
Edward Wang 2014-05-13 13:20:52 +08:00 committed by Alex Crichton
parent 655487b596
commit 5bf268d0b0
2 changed files with 12 additions and 3 deletions

View File

@ -239,7 +239,15 @@ fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@Pat]) -> useful {
return not_useful
}
let real_pat = match m.iter().find(|r| r.get(0).id != 0) {
Some(r) => *r.get(0), None => v[0]
Some(r) => {
match r.get(0).node {
// An arm of the form `ref x @ sub_pat` has type
// `sub_pat`, not `&sub_pat` as `x` itself does.
PatIdent(BindByRef(_), _, Some(sub)) => sub,
_ => *r.get(0)
}
}
None => v[0]
};
let left_ty = if real_pat.id == 0 { ty::mk_nil() }
else { ty::node_id_to_type(cx.tcx, real_pat.id) };

View File

@ -9,8 +9,9 @@
// except according to those terms.
fn main() {
let _x = match Some(1) {
_y @ Some(_) => 1,
let x = match Some(1) {
ref _y @ Some(_) => 1,
None => 2,
};
assert_eq!(x, 1);
}