Skip to content

Commit f78d2f5

Browse files
committed
auto merge of #15489 : jakub-/rust/issue-15488, r=pcwalton
Fixes #15488.
2 parents 179b2b4 + 9f460e7 commit f78d2f5

File tree

3 files changed

+56
-26
lines changed

3 files changed

+56
-26
lines changed

src/librustc/middle/check_match.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,7 @@ fn is_useful(cx: &MatchCheckCtxt, matrix @ &Matrix(ref rows): &Matrix,
411411
return NotUseful;
412412
}
413413
let real_pat = match rows.iter().find(|r| r.get(0).id != 0) {
414-
Some(r) => {
415-
match r.get(0).node {
416-
// An arm of the form `ref x @ sub_pat` has type
417-
// `sub_pat`, not `&sub_pat` as `x` itself does.
418-
PatIdent(BindByRef(_), _, Some(sub)) => sub,
419-
_ => *r.get(0)
420-
}
421-
}
414+
Some(r) => raw_pat(*r.get(0)),
422415
None if v.len() == 0 => return NotUseful,
423416
None => v[0]
424417
};

src/librustc/middle/trans/_match.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -413,26 +413,25 @@ fn expand_nested_bindings<'a, 'b>(
413413
let _indenter = indenter();
414414

415415
m.iter().map(|br| {
416-
match br.pats.get(col).node {
417-
ast::PatIdent(_, ref path1, Some(inner)) => {
418-
let pats = Vec::from_slice(br.pats.slice(0u, col))
419-
.append((vec!(inner))
420-
.append(br.pats.slice(col + 1u, br.pats.len())).as_slice());
421-
422-
let mut bound_ptrs = br.bound_ptrs.clone();
423-
bound_ptrs.push((path1.node, val));
424-
Match {
425-
pats: pats,
426-
data: &*br.data,
427-
bound_ptrs: bound_ptrs
428-
}
429-
}
430-
_ => Match {
431-
pats: br.pats.clone(),
432-
data: &*br.data,
433-
bound_ptrs: br.bound_ptrs.clone()
416+
let mut bound_ptrs = br.bound_ptrs.clone();
417+
let mut pat = *br.pats.get(col);
418+
loop {
419+
pat = match pat.node {
420+
ast::PatIdent(_, ref path, Some(inner)) => {
421+
bound_ptrs.push((path.node, val));
422+
inner.clone()
423+
},
424+
_ => break
434425
}
435426
}
427+
428+
let mut pats = br.pats.clone();
429+
*pats.get_mut(col) = pat;
430+
Match {
431+
pats: pats,
432+
data: &*br.data,
433+
bound_ptrs: bound_ptrs
434+
}
436435
}).collect()
437436
}
438437

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 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+
fn main() {
12+
let value = Some(1i);
13+
assert_eq!(match value {
14+
ref a @ Some(_) => a,
15+
ref b @ None => b
16+
}, &Some(1i));
17+
assert_eq!(match value {
18+
ref a @ ref _c @ Some(_) => a,
19+
ref b @ None => b
20+
}, &Some(1i));
21+
assert_eq!(match value {
22+
_a @ ref c @ Some(_) => c,
23+
ref b @ None => b
24+
}, &Some(1i));
25+
assert_eq!(match "foobarbaz" {
26+
_a @ b @ _ => b
27+
}, "foobarbaz");
28+
29+
let a @ b @ c = "foobarbaz";
30+
assert_eq!(a, "foobarbaz");
31+
assert_eq!(b, "foobarbaz");
32+
assert_eq!(c, "foobarbaz");
33+
let value = Some(true);
34+
let ref a @ b @ ref c = value;
35+
assert_eq!(a, &Some(true));
36+
assert_eq!(b, Some(true));
37+
assert_eq!(c, &Some(true));
38+
}

0 commit comments

Comments
 (0)