Skip to content

Remove the branch merging optimisations for slice patterns #16883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from Sep 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
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
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