Skip to content

Commit

Permalink
Fix #8391
Browse files Browse the repository at this point in the history
Closes #8391
  • Loading branch information
edwardw authored and alexcrichton committed May 14, 2014
1 parent 655487b commit 5bf268d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/librustc/middle/check_match.rs
Expand Up @@ -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) };
Expand Down
5 changes: 3 additions & 2 deletions src/test/run-pass/issue-8391.rs
Expand Up @@ -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);
}

0 comments on commit 5bf268d

Please sign in to comment.