@@ -265,7 +265,7 @@ pub fn is_useful(cx: @MatchCheckCtxt, +m: matrix, +v: &[@pat]) -> useful {
265
265
Some(ref ctor) => {
266
266
match is_useful(cx,
267
267
vec::filter_map(m, |r| default(cx, r)),
268
- vec:: tail(v )) {
268
+ v. tail()) {
269
269
useful_ => useful(left_ty, (/*bad*/copy *ctor)),
270
270
ref u => (/*bad*/copy *u)
271
271
}
@@ -281,7 +281,7 @@ pub fn is_useful(cx: @MatchCheckCtxt, +m: matrix, +v: &[@pat]) -> useful {
281
281
282
282
pub fn is_useful_specialized(cx: @MatchCheckCtxt,
283
283
m: matrix,
284
- + v: &[@pat],
284
+ v: &[@pat],
285
285
+ctor: ctor,
286
286
arity: uint,
287
287
lty: ty::t)
@@ -475,7 +475,7 @@ pub fn wild() -> @pat {
475
475
}
476
476
477
477
pub fn specialize(cx: @MatchCheckCtxt,
478
- + r: &[@pat],
478
+ r: &[@pat],
479
479
ctor_id: ctor,
480
480
arity: uint,
481
481
left_ty: ty::t)
@@ -485,13 +485,17 @@ pub fn specialize(cx: @MatchCheckCtxt,
485
485
match r0 {
486
486
pat{id: pat_id, node: n, span: pat_span} =>
487
487
match n {
488
- pat_wild => Some(vec::append(vec::from_elem(arity, wild()),
489
- vec::tail(r))),
488
+ pat_wild => {
489
+ Some(vec::append(vec::from_elem(arity, wild()), r.tail()))
490
+ }
490
491
pat_ident(_, _, _) => {
491
492
match cx.tcx.def_map.find(&pat_id) {
492
493
Some(def_variant(_, id)) => {
493
- if variant(id) == ctor_id { Some(vec::tail(r)) }
494
- else { None }
494
+ if variant(id) == ctor_id {
495
+ Some(vec::from_slice(r.tail()))
496
+ } else {
497
+ None
498
+ }
495
499
}
496
500
Some(def_const(did)) => {
497
501
let const_expr =
@@ -506,10 +510,20 @@ pub fn specialize(cx: @MatchCheckCtxt,
506
510
single => true,
507
511
_ => fail!(~" type error")
508
512
};
509
- if match_ { Some(vec::tail(r)) } else { None }
513
+ if match_ {
514
+ Some(vec::from_slice(r.tail()))
515
+ } else {
516
+ None
517
+ }
518
+ }
519
+ _ => {
520
+ Some(
521
+ vec::append(
522
+ vec::from_elem(arity, wild()),
523
+ r.tail()
524
+ )
525
+ )
510
526
}
511
- _ => Some(vec::append(vec::from_elem(arity, wild()),
512
- vec::tail(r)))
513
527
}
514
528
}
515
529
pat_enum(_, args) => {
@@ -519,7 +533,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
519
533
Some(args) => args,
520
534
None => vec::from_elem(arity, wild())
521
535
};
522
- Some(vec::append(args, vec::tail(r )))
536
+ Some(vec::append(args, vec::from_slice(r.tail() )))
523
537
}
524
538
def_variant(_, _) => None,
525
539
def_struct(*) => {
@@ -529,7 +543,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
529
543
Some(args) => new_args = args,
530
544
None => new_args = vec::from_elem(arity, wild())
531
545
}
532
- Some(vec::append(new_args, vec::tail(r )))
546
+ Some(vec::append(new_args, vec::from_slice(r.tail() )))
533
547
}
534
548
_ => None
535
549
}
@@ -545,7 +559,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
545
559
_ => wild()
546
560
}
547
561
});
548
- Some(vec::append(args, vec::tail(r )))
562
+ Some(vec::append(args, vec::from_slice(r.tail() )))
549
563
}
550
564
pat_struct(_, ref flds, _) => {
551
565
// Is this a struct or an enum variant?
@@ -560,7 +574,7 @@ pub fn specialize(cx: @MatchCheckCtxt,
560
574
_ => wild()
561
575
}
562
576
});
563
- Some(vec::append(args, vec::tail(r )))
577
+ Some(vec::append(args, vec::from_slice(r.tail() )))
564
578
} else {
565
579
None
566
580
}
@@ -587,13 +601,14 @@ pub fn specialize(cx: @MatchCheckCtxt,
587
601
_ => wild()
588
602
}
589
603
});
590
- Some(vec::append(args, vec::tail(r )))
604
+ Some(vec::append(args, vec::from_slice(r.tail() )))
591
605
}
592
606
}
593
607
}
594
- pat_tup(args) => Some(vec::append(args, vec::tail(r))),
595
- pat_box(a) | pat_uniq(a) | pat_region(a) =>
596
- Some(vec::append(~[a], vec::tail(r))),
608
+ pat_tup(args) => Some(vec::append(args, r.tail())),
609
+ pat_box(a) | pat_uniq(a) | pat_region(a) => {
610
+ Some(vec::append(~[a], r.tail()))
611
+ }
597
612
pat_lit(expr) => {
598
613
let e_v = eval_const_expr(cx.tcx, expr);
599
614
let match_ = match ctor_id {
@@ -605,21 +620,21 @@ pub fn specialize(cx: @MatchCheckCtxt,
605
620
single => true,
606
621
_ => fail!(~" type error")
607
622
};
608
- if match_ { Some(vec::tail(r )) } else { None }
623
+ if match_ { Some(vec::from_slice(r.tail() )) } else { None }
609
624
}
610
625
pat_range(lo, hi) => {
611
626
let (c_lo, c_hi) = match ctor_id {
612
627
val(ref v) => ((/*bad*/copy *v), (/*bad*/copy *v)),
613
628
range(ref lo, ref hi) =>
614
629
((/*bad*/copy *lo), (/*bad*/copy *hi)),
615
- single => return Some(vec::tail(r )),
630
+ single => return Some(vec::from_slice(r.tail() )),
616
631
_ => fail!(~" type error")
617
632
};
618
633
let v_lo = eval_const_expr(cx.tcx, lo),
619
634
v_hi = eval_const_expr(cx.tcx, hi);
620
635
let match_ = compare_const_vals(c_lo, v_lo) >= 0 &&
621
636
compare_const_vals(c_hi, v_hi) <= 0;
622
- if match_ { Some(vec::tail(r )) } else { None }
637
+ if match_ { Some(vec::from_slice(r.tail() )) } else { None }
623
638
}
624
639
pat_vec(elems, tail) => {
625
640
match ctor_id {
@@ -630,10 +645,10 @@ pub fn specialize(cx: @MatchCheckCtxt,
630
645
vec::append(elems, vec::from_elem(
631
646
arity - num_elements, wild()
632
647
)),
633
- vec::tail(r )
648
+ vec::from_slice(r.tail() )
634
649
))
635
650
} else if num_elements == arity {
636
- Some(vec::append(elems, vec:: tail(r )))
651
+ Some(vec::append(elems, r. tail()))
637
652
} else {
638
653
None
639
654
}
@@ -645,8 +660,8 @@ pub fn specialize(cx: @MatchCheckCtxt,
645
660
}
646
661
}
647
662
648
- pub fn default(cx: @MatchCheckCtxt, r: ~ [@pat]) -> Option<~[@pat]> {
649
- if is_wild(cx, r[0]) { Some(vec::tail(r )) }
663
+ pub fn default(cx: @MatchCheckCtxt, r: & [@pat]) -> Option<~[@pat]> {
664
+ if is_wild(cx, r[0]) { Some(vec::from_slice(r.tail() )) }
650
665
else { None }
651
666
}
652
667
0 commit comments