Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix #8391
Closes #8391
  • Loading branch information
edwardw committed May 13, 2014
commit ef6beb38ae7860ee20b880fd00d2418f59a36f9e
10 changes: 9 additions & 1 deletion src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
}