Skip to content

Commit ef6beb3

Browse files
committed
1 parent edae0bd commit ef6beb3

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/librustc/middle/check_match.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,15 @@ fn is_useful(cx: &MatchCheckCtxt, m: &matrix, v: &[@Pat]) -> useful {
239239
return not_useful
240240
}
241241
let real_pat = match m.iter().find(|r| r.get(0).id != 0) {
242-
Some(r) => *r.get(0), None => v[0]
242+
Some(r) => {
243+
match r.get(0).node {
244+
// An arm of the form `ref x @ sub_pat` has type
245+
// `sub_pat`, not `&sub_pat` as `x` itself does.
246+
PatIdent(BindByRef(_), _, Some(sub)) => sub,
247+
_ => *r.get(0)
248+
}
249+
}
250+
None => v[0]
243251
};
244252
let left_ty = if real_pat.id == 0 { ty::mk_nil() }
245253
else { ty::node_id_to_type(cx.tcx, real_pat.id) };

src/test/run-pass/issue-8391.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
let _x = match Some(1) {
13-
_y @ Some(_) => 1,
12+
let x = match Some(1) {
13+
ref _y @ Some(_) => 1,
1414
None => 2,
1515
};
16+
assert_eq!(x, 1);
1617
}

0 commit comments

Comments
 (0)