Skip to content

Commit 5924937

Browse files
committed
auto merge of #16883 : jakub-/rust/issue-16648, r=pcwalton
They were only correct in the simplest case. Some of the optimisations are certainly possible but should be introduced carefully and only when the whole pattern codegen infrastructure is in a better shape. Fixes #16648.
2 parents 1f49e02 + 6f35ede commit 5924937

File tree

7 files changed

+334
-364
lines changed

7 files changed

+334
-364
lines changed

src/librustc/middle/check_match.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ use syntax::codemap::{Span, Spanned, DUMMY_SP};
2828
use syntax::fold::{Folder, noop_fold_pat};
2929
use syntax::print::pprust::pat_to_string;
3030
use syntax::parse::token;
31-
use syntax::visit;
32-
use syntax::visit::{Visitor, FnKind};
31+
use syntax::visit::{mod, Visitor, FnKind};
3332
use util::ppaux::ty_to_string;
3433

3534
struct Matrix(Vec<Vec<Gc<Pat>>>);
@@ -103,7 +102,9 @@ pub enum Constructor {
103102
/// Ranges of literal values (2..5).
104103
ConstantRange(const_val, const_val),
105104
/// Array patterns of length n.
106-
Slice(uint)
105+
Slice(uint),
106+
/// Array patterns with a subslice.
107+
SliceWithSubslice(uint, uint)
107108
}
108109

109110
#[deriving(Clone, PartialEq)]
@@ -270,13 +271,6 @@ fn check_arms(cx: &MatchCheckCtxt, arms: &[Arm]) {
270271
}
271272
}
272273

273-
fn raw_pat(p: Gc<Pat>) -> Gc<Pat> {
274-
match p.node {
275-
PatIdent(_, _, Some(s)) => { raw_pat(s) }
276-
_ => { p }
277-
}
278-
}
279-
280274
fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix) {
281275
match is_useful(cx, matrix, [wild()], ConstructWitness) {
282276
UsefulWithWitness(pats) => {
@@ -821,6 +815,14 @@ pub fn specialize(cx: &MatchCheckCtxt, r: &[Gc<Pat>],
821815
pats.push_all(after.as_slice());
822816
Some(pats)
823817
},
818+
SliceWithSubslice(prefix, suffix)
819+
if before.len() == prefix
820+
&& after.len() == suffix
821+
&& slice.is_some() => {
822+
let mut pats = before.clone();
823+
pats.push_all(after.as_slice());
824+
Some(pats)
825+
}
824826
_ => None
825827
}
826828
}

src/librustc/middle/pat_util.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ pub fn wild() -> Gc<Pat> {
119119
box (GC) Pat { id: 0, node: PatWild(PatWildSingle), span: DUMMY_SP }
120120
}
121121

122+
pub fn raw_pat(p: Gc<Pat>) -> Gc<Pat> {
123+
match p.node {
124+
PatIdent(_, _, Some(s)) => { raw_pat(s) }
125+
_ => { p }
126+
}
127+
}
128+
122129
pub fn def_to_path(tcx: &ty::ctxt, id: DefId) -> Path {
123130
ty::with_path(tcx, id, |mut path| Path {
124131
global: false,

0 commit comments

Comments
 (0)