1
- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1
+ // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2
2
// file at the top-level directory of this distribution and at
3
3
// http://rust-lang.org/COPYRIGHT.
4
4
//
@@ -498,10 +498,27 @@ pub fn specialize(cx: @MatchCheckCtxt,
498
498
lookup_const_by_id ( cx. tcx , did) . get ( ) ;
499
499
let e_v = eval_const_expr ( cx. tcx , const_expr) ;
500
500
let match_ = match * ctor_id {
501
- val( ref v) => compare_const_vals ( & e_v, v) == 0 ,
501
+ val( ref v) => {
502
+ match compare_const_vals ( & e_v, v) {
503
+ Some ( val1) => ( val1 == 0 ) ,
504
+ None => {
505
+ cx. tcx . sess . span_err ( pat_span,
506
+ "mismatched types between arms" ) ;
507
+ false
508
+ }
509
+ }
510
+ } ,
502
511
range( ref c_lo, ref c_hi) => {
503
- compare_const_vals ( c_lo, & e_v) >= 0 &&
504
- compare_const_vals ( c_hi, & e_v) <= 0
512
+ let m1 = compare_const_vals ( c_lo, & e_v) ,
513
+ m2 = compare_const_vals ( c_hi, & e_v) ;
514
+ match ( m1, m2) {
515
+ ( Some ( val1) , Some ( val2) ) => ( val1 >= 0 && val2 <= 0 ) ,
516
+ _ => {
517
+ cx. tcx . sess . span_err ( pat_span,
518
+ "mismatched types between ranges" ) ;
519
+ false
520
+ }
521
+ }
505
522
}
506
523
single => true ,
507
524
_ => fail ! ( "type error" )
@@ -529,10 +546,26 @@ pub fn specialize(cx: @MatchCheckCtxt,
529
546
lookup_const_by_id ( cx. tcx , did) . get ( ) ;
530
547
let e_v = eval_const_expr ( cx. tcx , const_expr) ;
531
548
let match_ = match * ctor_id {
532
- val( ref v) => compare_const_vals ( & e_v, v) == 0 ,
549
+ val( ref v) =>
550
+ match compare_const_vals ( & e_v, v) {
551
+ Some ( val1) => ( val1 == 0 ) ,
552
+ None => {
553
+ cx. tcx . sess . span_err ( pat_span,
554
+ "mismatched types between arms" ) ;
555
+ false
556
+ }
557
+ } ,
533
558
range( ref c_lo, ref c_hi) => {
534
- compare_const_vals ( c_lo, & e_v) >= 0 &&
535
- compare_const_vals ( c_hi, & e_v) <= 0
559
+ let m1 = compare_const_vals ( c_lo, & e_v) ,
560
+ m2 = compare_const_vals ( c_hi, & e_v) ;
561
+ match ( m1, m2) {
562
+ ( Some ( val1) , Some ( val2) ) => ( val1 >= 0 && val2 <= 0 ) ,
563
+ _ => {
564
+ cx. tcx . sess . span_err ( pat_span,
565
+ "mismatched types between ranges" ) ;
566
+ false
567
+ }
568
+ }
536
569
}
537
570
single => true ,
538
571
_ => fail ! ( "type error" )
@@ -619,10 +652,27 @@ pub fn specialize(cx: @MatchCheckCtxt,
619
652
pat_lit( expr) => {
620
653
let e_v = eval_const_expr ( cx. tcx , expr) ;
621
654
let match_ = match * ctor_id {
622
- val( ref v) => compare_const_vals ( & e_v, v) == 0 ,
655
+ val( ref v) => {
656
+ match compare_const_vals ( & e_v, v) {
657
+ Some ( val1) => val1 == 0 ,
658
+ None => {
659
+ cx. tcx . sess . span_err ( pat_span,
660
+ "mismatched types between arms" ) ;
661
+ false
662
+ }
663
+ }
664
+ } ,
623
665
range( ref c_lo, ref c_hi) => {
624
- compare_const_vals ( c_lo, & e_v) >= 0 &&
625
- compare_const_vals ( c_hi, & e_v) <= 0
666
+ let m1 = compare_const_vals ( c_lo, & e_v) ,
667
+ m2 = compare_const_vals ( c_hi, & e_v) ;
668
+ match ( m1, m2) {
669
+ ( Some ( val1) , Some ( val2) ) => ( val1 >= 0 && val2 <= 0 ) ,
670
+ _ => {
671
+ cx. tcx . sess . span_err ( pat_span,
672
+ "mismatched types between ranges" ) ;
673
+ false
674
+ }
675
+ }
626
676
}
627
677
single => true ,
628
678
_ => fail ! ( "type error" )
@@ -638,11 +688,22 @@ pub fn specialize(cx: @MatchCheckCtxt,
638
688
_ => fail ! ( "type error" )
639
689
} ;
640
690
let v_lo = eval_const_expr ( cx. tcx , lo) ,
641
- v_hi = eval_const_expr ( cx. tcx , hi) ;
642
- let match_ = compare_const_vals ( & c_lo, & v_lo) >= 0 &&
643
- compare_const_vals ( & c_hi, & v_hi) <= 0 ;
644
- if match_ { Some ( vec:: to_owned ( r. tail ( ) ) ) } else { None }
645
- }
691
+ v_hi = eval_const_expr ( cx. tcx , hi) ;
692
+
693
+ let m1 = compare_const_vals ( & c_lo, & v_lo) ,
694
+ m2 = compare_const_vals ( & c_hi, & v_hi) ;
695
+ match ( m1, m2) {
696
+ ( Some ( val1) , Some ( val2) ) if val1 >= 0 && val2 <= 0 => {
697
+ Some ( vec:: to_owned ( r. tail ( ) ) )
698
+ } ,
699
+ ( Some ( _) , Some ( _) ) => None ,
700
+ _ => {
701
+ cx. tcx . sess . span_err ( pat_span,
702
+ "mismatched types between ranges" ) ;
703
+ None
704
+ }
705
+ }
706
+ }
646
707
pat_vec( before, slice, after) => {
647
708
match * ctor_id {
648
709
vec( _) => {
0 commit comments