Skip to content

Commit 0ea031b

Browse files
committed
librustc: Remove record patterns from the compiler
1 parent 954ae9c commit 0ea031b

File tree

15 files changed

+31
-74
lines changed

15 files changed

+31
-74
lines changed

src/librustc/middle/check_match.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,7 @@ pub fn pat_ctor_id(cx: @MatchCheckCtxt, p: @pat) -> Option<ctor> {
319319
_ => Some(single)
320320
}
321321
}
322-
pat_box(_) | pat_uniq(_) | pat_rec(_, _) | pat_tup(_) |
323-
pat_region(*) => {
322+
pat_box(_) | pat_uniq(_) | pat_tup(_) | pat_region(*) => {
324323
Some(single)
325324
}
326325
pat_vec(elems, tail) => {
@@ -547,7 +546,6 @@ pub fn specialize(cx: @MatchCheckCtxt,
547546
_ => None
548547
}
549548
}
550-
pat_rec(ref flds, _) => fail!(),
551549
pat_struct(_, ref flds, _) => {
552550
// Is this a struct or an enum variant?
553551
match cx.tcx.def_map.get(&pat_id) {
@@ -709,9 +707,6 @@ pub fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool {
709707
false
710708
}
711709
pat_lit(_) | pat_range(_, _) => { true }
712-
pat_rec(fields, _) => {
713-
fields.any(|f| is_refutable(cx, f.pat))
714-
}
715710
pat_struct(_, fields, _) => {
716711
fields.any(|f| is_refutable(cx, f.pat))
717712
}

src/librustc/middle/mem_categorization.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,6 @@ pub impl mem_categorization_ctxt {
942942
// nullary variant or identifier: ignore
943943
}
944944

945-
ast::pat_rec(ref field_pats, _) |
946945
ast::pat_struct(_, ref field_pats, _) => {
947946
// {f1: p1, ..., fN: pN}
948947
for field_pats.each |fp| {

src/librustc/middle/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use syntax::ast::{item_const, item_enum, item_fn, item_foreign_mod};
4747
use syntax::ast::{item_impl, item_mac, item_mod, item_trait, item_ty, le};
4848
use syntax::ast::{local, local_crate, lt, method, mode, module_ns, mul};
4949
use syntax::ast::{named_field, ne, neg, node_id, pat, pat_enum, pat_ident};
50-
use syntax::ast::{path, pat_box, pat_lit, pat_range, pat_rec, pat_struct};
50+
use syntax::ast::{path, pat_box, pat_lit, pat_range, pat_struct};
5151
use syntax::ast::{pat_tup, pat_uniq, pat_wild, prim_ty, private, provided};
5252
use syntax::ast::{public, required, rem, self_ty_, shl, shr, stmt_decl};
5353
use syntax::ast::{struct_dtor, struct_field, struct_variant_kind, sty_by_ref};

src/librustc/middle/trans/_match.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,7 @@ pub fn enter_default(bcx: block, dm: DefMap, m: &[@Match/&r],
459459
460460
do enter_match(bcx, dm, m, col, val) |p| {
461461
match p.node {
462-
ast::pat_wild | ast::pat_rec(_, _) | ast::pat_tup(_) |
463-
ast::pat_struct(*) => Some(~[]),
462+
ast::pat_wild | ast::pat_tup(_) | ast::pat_struct(*) => Some(~[]),
464463
ast::pat_ident(_, _, None) if pat_is_binding(dm, p) => Some(~[]),
465464
_ => None
466465
}
@@ -611,7 +610,7 @@ pub fn enter_rec_or_struct(bcx: block,
611610
let dummy = @ast::pat {id: 0, node: ast::pat_wild, span: dummy_sp()};
612611
do enter_match(bcx, dm, m, col, val) |p| {
613612
match /*bad*/copy p.node {
614-
ast::pat_rec(fpats, _) | ast::pat_struct(_, fpats, _) => {
613+
ast::pat_struct(_, fpats, _) => {
615614
let mut pats = ~[];
616615
for vec::each(fields) |fname| {
617616
match fpats.find(|p| p.ident == *fname) {
@@ -887,7 +886,6 @@ pub fn collect_record_or_struct_fields(bcx: block,
887886
let mut fields: ~[ast::ident] = ~[];
888887
for vec::each(m) |br| {
889888
match /*bad*/copy br.pats[col].node {
890-
ast::pat_rec(fs, _) => extend(&mut fields, fs),
891889
ast::pat_struct(_, fs, _) => {
892890
match ty::get(node_id_type(bcx, br.pats[col].id)).sty {
893891
ty::ty_struct(*) => extend(&mut fields, fs),
@@ -1766,7 +1764,7 @@ pub fn bind_irrefutable_pat(bcx: block,
17661764
}
17671765
}
17681766
}
1769-
ast::pat_rec(fields, _) | ast::pat_struct(_, fields, _) => {
1767+
ast::pat_struct(_, fields, _) => {
17701768
let tcx = bcx.tcx();
17711769
let pat_ty = node_id_type(bcx, pat.id);
17721770
let pat_repr = adt::represent_type(bcx.ccx(), pat_ty);

src/librustc/middle/trans/adt.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ pub fn represent_type(cx: @CrateContext, t: ty::t) -> @Repr {
155155
Unit(cases[0].discr)
156156
} else if cases.len() == 1 {
157157
// Equivalent to a struct/tuple/newtype.
158-
assert cases[0].discr == 0;
158+
fail_unless!(cases[0].discr == 0);
159159
Univariant(mk_struct(cx, cases[0].tys), NonStruct)
160160
} else if cases.all(|c| c.tys.len() == 0) {
161161
// All bodies empty -> intlike
@@ -302,18 +302,18 @@ pub fn trans_case(bcx: block, r: &Repr, discr: int) -> _match::opt_result {
302302
pub fn trans_start_init(bcx: block, r: &Repr, val: ValueRef, discr: int) {
303303
match *r {
304304
Unit(the_discr) => {
305-
assert discr == the_discr;
305+
fail_unless!(discr == the_discr);
306306
}
307307
CEnum(min, max) => {
308-
assert min <= discr && discr <= max;
308+
fail_unless!(min <= discr && discr <= max);
309309
Store(bcx, C_int(bcx.ccx(), discr), GEPi(bcx, val, [0, 0]))
310310
}
311311
Univariant(_, StructWithDtor) => {
312-
assert discr == 0;
312+
fail_unless!(discr == 0);
313313
Store(bcx, C_u8(1), GEPi(bcx, val, [0, 1]))
314314
}
315315
Univariant(*) => {
316-
assert discr == 0;
316+
fail_unless!(discr == 0);
317317
}
318318
General(*) => {
319319
Store(bcx, C_int(bcx.ccx(), discr), GEPi(bcx, val, [0, 0]))
@@ -328,7 +328,7 @@ pub fn trans_start_init(bcx: block, r: &Repr, val: ValueRef, discr: int) {
328328
pub fn num_args(r: &Repr, discr: int) -> uint {
329329
match *r {
330330
Unit(*) | CEnum(*) => 0,
331-
Univariant(ref st, _dt) => { assert discr == 0; st.fields.len() }
331+
Univariant(ref st, _) => { fail_unless!(discr == 0); st.fields.len() }
332332
General(ref cases) => cases[discr as uint].fields.len()
333333
}
334334
}
@@ -344,7 +344,7 @@ pub fn trans_field_ptr(bcx: block, r: &Repr, val: ValueRef, discr: int,
344344
bcx.ccx().sess.bug(~"element access in C-like enum")
345345
}
346346
Univariant(ref st, dt) => {
347-
assert discr == 0;
347+
fail_unless!(discr == 0);
348348
let val = match dt {
349349
NonStruct => val,
350350
StructWithDtor | StructWithoutDtor => GEPi(bcx, val, [0, 0])
@@ -411,12 +411,12 @@ pub fn trans_const(ccx: @CrateContext, r: &Repr, discr: int,
411411
C_struct(~[])
412412
}
413413
CEnum(min, max) => {
414-
assert vals.len() == 0;
415-
assert min <= discr && discr <= max;
414+
fail_unless!(vals.len() == 0);
415+
fail_unless!(min <= discr && discr <= max);
416416
C_int(ccx, discr)
417417
}
418418
Univariant(ref st, dt) => {
419-
assert discr == 0;
419+
fail_unless!(discr == 0);
420420
let s = C_struct(build_const_struct(ccx, st, vals));
421421
match dt {
422422
NonStruct => s,
@@ -452,7 +452,7 @@ pub fn trans_const(ccx: @CrateContext, r: &Repr, discr: int,
452452
*/
453453
fn build_const_struct(ccx: @CrateContext, st: &Struct, vals: &[ValueRef])
454454
-> ~[ValueRef] {
455-
assert vals.len() == st.fields.len();
455+
fail_unless!(vals.len() == st.fields.len());
456456

457457
let mut offset = 0;
458458
let mut cfields = ~[];
@@ -468,7 +468,7 @@ fn build_const_struct(ccx: @CrateContext, st: &Struct, vals: &[ValueRef])
468468
cfields.push(padding(target_offset - offset));
469469
offset = target_offset;
470470
}
471-
assert !is_undef(vals[i]);
471+
fail_unless!(!is_undef(vals[i]));
472472
// If that assert fails, could change it to wrap in a struct?
473473
// (See `const_struct_field` for why real fields must not be undef.)
474474
cfields.push(vals[i]);

src/librustc/middle/trans/datum.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ pub impl Datum {
679679
}
680680

681681
let repr = adt::represent_type(ccx, self.ty);
682-
assert adt::is_newtypeish(repr);
682+
fail_unless!(adt::is_newtypeish(repr));
683683
let ty = ty::subst(ccx.tcx, substs, variants[0].args[0]);
684684
return match self.mode {
685685
ByRef => {
@@ -719,7 +719,7 @@ pub impl Datum {
719719
}
720720

721721
let repr = adt::represent_type(ccx, self.ty);
722-
assert adt::is_newtypeish(repr);
722+
fail_unless!(adt::is_newtypeish(repr));
723723
let ty = fields[0].mt.ty;
724724
return match self.mode {
725725
ByRef => {

src/librustc/middle/typeck/check/_match.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,6 @@ pub fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) {
414414
ast::pat_enum(path, subpats) => {
415415
check_pat_variant(pcx, pat, path, subpats, expected);
416416
}
417-
ast::pat_rec(fields, etc) => {
418-
tcx.sess.span_fatal
419-
(pat.span,
420-
fmt!("mismatched types: expected `%s` but found record",
421-
fcx.infcx().ty_to_str(expected)));
422-
}
423417
ast::pat_struct(path, fields, etc) => {
424418
// Grab the class data that we care about.
425419
let structure = structure_of(fcx, pat.span, expected);

src/librustc/middle/typeck/check/regionck.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,6 @@ pub mod guarantor {
874874
}
875875
}
876876
ast::pat_enum(*) => {}
877-
ast::pat_rec(ref fpats, _) |
878877
ast::pat_struct(_, ref fpats, _) => {
879878
for fpats.each |fpat| {
880879
link_ref_bindings_in_pat(rcx, fpat.pat, guarantor);

src/libsyntax/ast.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,6 @@ pub enum pat_ {
302302
pat_ident(binding_mode, @path, Option<@pat>),
303303
pat_enum(@path, Option<~[@pat]>), /* "none" means a * pattern where
304304
* we don't bind the fields to names */
305-
pat_rec(~[field_pat], bool),
306305
pat_struct(@path, ~[field_pat], bool),
307306
pat_tup(~[@pat]),
308307
pat_box(@pat),

src/libsyntax/ast_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ pub fn walk_pat(pat: @pat, it: fn(@pat)) {
520520
it(pat);
521521
match pat.node {
522522
pat_ident(_, _, Some(p)) => walk_pat(p, it),
523-
pat_rec(ref fields, _) | pat_struct(_, ref fields, _) => {
523+
pat_struct(_, ref fields, _) => {
524524
for fields.each |f| {
525525
walk_pat(f.pat, it)
526526
}

0 commit comments

Comments
 (0)