Skip to content

Commit

Permalink
auto merge of #16883 : jakub-/rust/issue-16648, r=pcwalton
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Sep 4, 2014
2 parents 1f49e02 + 6f35ede commit 5924937
Show file tree
Hide file tree
Showing 7 changed files with 334 additions and 364 deletions.
22 changes: 12 additions & 10 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ use syntax::codemap::{Span, Spanned, DUMMY_SP};
use syntax::fold::{Folder, noop_fold_pat};
use syntax::print::pprust::pat_to_string;
use syntax::parse::token;
use syntax::visit;
use syntax::visit::{Visitor, FnKind};
use syntax::visit::{mod, Visitor, FnKind};
use util::ppaux::ty_to_string;

struct Matrix(Vec<Vec<Gc<Pat>>>);
Expand Down Expand Up @@ -103,7 +102,9 @@ pub enum Constructor {
/// Ranges of literal values (2..5).
ConstantRange(const_val, const_val),
/// Array patterns of length n.
Slice(uint)
Slice(uint),
/// Array patterns with a subslice.
SliceWithSubslice(uint, uint)
}

#[deriving(Clone, PartialEq)]
Expand Down Expand Up @@ -270,13 +271,6 @@ fn check_arms(cx: &MatchCheckCtxt, arms: &[Arm]) {
}
}

fn raw_pat(p: Gc<Pat>) -> Gc<Pat> {
match p.node {
PatIdent(_, _, Some(s)) => { raw_pat(s) }
_ => { p }
}
}

fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, matrix: &Matrix) {
match is_useful(cx, matrix, [wild()], ConstructWitness) {
UsefulWithWitness(pats) => {
Expand Down Expand Up @@ -821,6 +815,14 @@ pub fn specialize(cx: &MatchCheckCtxt, r: &[Gc<Pat>],
pats.push_all(after.as_slice());
Some(pats)
},
SliceWithSubslice(prefix, suffix)
if before.len() == prefix
&& after.len() == suffix
&& slice.is_some() => {
let mut pats = before.clone();
pats.push_all(after.as_slice());
Some(pats)
}
_ => None
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/librustc/middle/pat_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ pub fn wild() -> Gc<Pat> {
box (GC) Pat { id: 0, node: PatWild(PatWildSingle), span: DUMMY_SP }
}

pub fn raw_pat(p: Gc<Pat>) -> Gc<Pat> {
match p.node {
PatIdent(_, _, Some(s)) => { raw_pat(s) }
_ => { p }
}
}

pub fn def_to_path(tcx: &ty::ctxt, id: DefId) -> Path {
ty::with_path(tcx, id, |mut path| Path {
global: false,
Expand Down
Loading

0 comments on commit 5924937

Please sign in to comment.