Skip to content

Improve code reuse between trans/_match.rs and check_match.rs #15078

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 Jul 3, 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
2 changes: 0 additions & 2 deletions src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -2155,8 +2155,6 @@ These are functions:

* `str_eq`
: Compare two strings (`&str`) for equality.
* `uniq_str_eq`
: Compare two owned strings (`String`) for equality.
* `strdup_uniq`
: Return a new unique string
containing a copy of the contents of a unique string.
Expand Down
20 changes: 10 additions & 10 deletions src/librustc/middle/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ impl fmt::Show for Matrix {
}
}

struct MatchCheckCtxt<'a> {
tcx: &'a ty::ctxt
pub struct MatchCheckCtxt<'a> {
pub tcx: &'a ty::ctxt
}

#[deriving(Clone, PartialEq)]
enum Constructor {
pub enum Constructor {
/// The constructor of all patterns that don't vary by constructor,
/// e.g. struct patterns and fixed-length arrays.
Single,
Expand Down Expand Up @@ -492,9 +492,9 @@ fn is_useful_specialized(cx: &MatchCheckCtxt, &Matrix(ref m): &Matrix, v: &[Gc<P
ctor: Constructor, lty: ty::t, witness: WitnessPreference) -> Usefulness {
let arity = constructor_arity(cx, &ctor, lty);
let matrix = Matrix(m.iter().filter_map(|r| {
specialize(cx, r.as_slice(), &ctor, arity)
specialize(cx, r.as_slice(), &ctor, 0u, arity)
}).collect());
match specialize(cx, v, &ctor, arity) {
match specialize(cx, v, &ctor, 0u, arity) {
Some(v) => is_useful(cx, &matrix, v.as_slice(), witness),
None => NotUseful
}
Expand Down Expand Up @@ -580,7 +580,7 @@ fn is_wild(cx: &MatchCheckCtxt, p: Gc<Pat>) -> bool {
///
/// For instance, a tuple pattern (_, 42u, Some([])) has the arity of 3.
/// A struct pattern's arity is the number of fields it contains, etc.
fn constructor_arity(cx: &MatchCheckCtxt, ctor: &Constructor, ty: ty::t) -> uint {
pub fn constructor_arity(cx: &MatchCheckCtxt, ctor: &Constructor, ty: ty::t) -> uint {
match ty::get(ty).sty {
ty::ty_tup(ref fs) => fs.len(),
ty::ty_box(_) | ty::ty_uniq(_) => 1u,
Expand Down Expand Up @@ -628,11 +628,11 @@ fn range_covered_by_constructor(ctor: &Constructor,
/// different patterns.
/// Structure patterns with a partial wild pattern (Foo { a: 42, .. }) have their missing
/// fields filled with wild patterns.
fn specialize(cx: &MatchCheckCtxt, r: &[Gc<Pat>],
constructor: &Constructor, arity: uint) -> Option<Vec<Gc<Pat>>> {
pub fn specialize(cx: &MatchCheckCtxt, r: &[Gc<Pat>],
constructor: &Constructor, col: uint, arity: uint) -> Option<Vec<Gc<Pat>>> {
let &Pat {
id: pat_id, node: ref node, span: pat_span
} = &(*raw_pat(r[0]));
} = &(*raw_pat(r[col]));
let head: Option<Vec<Gc<Pat>>> = match node {
&PatWild =>
Some(Vec::from_elem(arity, wild())),
Expand Down Expand Up @@ -776,7 +776,7 @@ fn specialize(cx: &MatchCheckCtxt, r: &[Gc<Pat>],
None
}
};
head.map(|head| head.append(r.tail()))
head.map(|head| head.append(r.slice_to(col)).append(r.slice_from(col + 1)))
}

fn default(cx: &MatchCheckCtxt, r: &[Gc<Pat>]) -> Option<Vec<Gc<Pat>>> {
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ lets_do_this! {
OrdTraitLangItem, "ord", ord_trait;

StrEqFnLangItem, "str_eq", str_eq_fn;
UniqStrEqFnLangItem, "uniq_str_eq", uniq_str_eq_fn;

// A number of failure-related lang items. The `fail_` item corresponds to
// divide-by-zero and various failure cases with `match`. The
Expand Down
Loading