@@ -98,12 +98,22 @@ impl FontRelativeLength {
98
98
99
99
fn try_sum ( & self , other : & Self ) -> Result < Self , ( ) > {
100
100
use self :: FontRelativeLength :: * ;
101
+
102
+ if std:: mem:: discriminant ( self ) != std:: mem:: discriminant ( other) {
103
+ return Err ( ( ) ) ;
104
+ }
105
+
101
106
Ok ( match ( self , other) {
102
107
( & Em ( one) , & Em ( other) ) => Em ( one + other) ,
103
108
( & Ex ( one) , & Ex ( other) ) => Ex ( one + other) ,
104
109
( & Ch ( one) , & Ch ( other) ) => Ch ( one + other) ,
105
110
( & Rem ( one) , & Rem ( other) ) => Rem ( one + other) ,
106
- _ => return Err ( ( ) ) ,
111
+
112
+
113
+ _ => unsafe {
114
+ match * self { Em ( ..) | Ex ( ..) | Ch ( ..) | Rem ( ..) => { } }
115
+ debug_unreachable ! ( "Forgot to handle unit in try_sum()" )
116
+ } ,
107
117
} )
108
118
}
109
119
@@ -260,12 +270,22 @@ impl ViewportPercentageLength {
260
270
261
271
fn try_sum ( & self , other : & Self ) -> Result < Self , ( ) > {
262
272
use self :: ViewportPercentageLength :: * ;
273
+
274
+ if std:: mem:: discriminant ( self ) != std:: mem:: discriminant ( other) {
275
+ return Err ( ( ) ) ;
276
+ }
277
+
263
278
Ok ( match ( self , other) {
264
279
( & Vw ( one) , & Vw ( other) ) => Vw ( one + other) ,
265
280
( & Vh ( one) , & Vh ( other) ) => Vh ( one + other) ,
266
281
( & Vmin ( one) , & Vmin ( other) ) => Vmin ( one + other) ,
267
282
( & Vmax ( one) , & Vmax ( other) ) => Vmax ( one + other) ,
268
- _ => return Err ( ( ) ) ,
283
+
284
+
285
+ _ => unsafe {
286
+ match * self { Vw ( ..) | Vh ( ..) | Vmin ( ..) | Vmax ( ..) => { } }
287
+ debug_unreachable ! ( "Forgot to handle unit in try_sum()" )
288
+ } ,
269
289
} )
270
290
}
271
291
@@ -500,14 +520,23 @@ impl NoCalcLength {
500
520
pub ( crate ) fn try_sum ( & self , other : & Self ) -> Result < Self , ( ) > {
501
521
use self :: NoCalcLength :: * ;
502
522
523
+ if std:: mem:: discriminant ( self ) != std:: mem:: discriminant ( other) {
524
+ return Err ( ( ) ) ;
525
+ }
526
+
503
527
Ok ( match ( self , other) {
504
528
( & Absolute ( ref one) , & Absolute ( ref other) ) => Absolute ( * one + * other) ,
505
529
( & FontRelative ( ref one) , & FontRelative ( ref other) ) => FontRelative ( one. try_sum ( other) ?) ,
506
530
( & ViewportPercentage ( ref one) , & ViewportPercentage ( ref other) ) => ViewportPercentage ( one. try_sum ( other) ?) ,
507
531
( & ServoCharacterWidth ( ref one) , & ServoCharacterWidth ( ref other) ) => {
508
532
ServoCharacterWidth ( CharacterWidth ( one. 0 + other. 0 ) )
509
533
} ,
510
- _ => return Err ( ( ) ) ,
534
+
535
+
536
+ _ => unsafe {
537
+ match * self { Absolute ( ..) | FontRelative ( ..) | ViewportPercentage ( ..) | ServoCharacterWidth ( ..) => { } }
538
+ debug_unreachable ! ( "Forgot to handle unit in try_sum()" )
539
+ } ,
511
540
} )
512
541
}
513
542
@@ -532,17 +561,22 @@ impl SpecifiedValueInfo for NoCalcLength {}
532
561
impl PartialOrd for NoCalcLength {
533
562
fn partial_cmp ( & self , other : & Self ) -> Option < cmp:: Ordering > {
534
563
use self :: NoCalcLength :: * ;
564
+
565
+ if std:: mem:: discriminant ( self ) != std:: mem:: discriminant ( other) {
566
+ return None ;
567
+ }
568
+
535
569
match ( self , other) {
536
570
( & Absolute ( ref one) , & Absolute ( ref other) ) => one. to_px ( ) . partial_cmp ( & other. to_px ( ) ) ,
537
571
( & FontRelative ( ref one) , & FontRelative ( ref other) ) => one. partial_cmp ( other) ,
538
572
( & ViewportPercentage ( ref one) , & ViewportPercentage ( ref other) ) => one. partial_cmp ( other) ,
539
573
( & ServoCharacterWidth ( ref one) , & ServoCharacterWidth ( ref other) ) => one. 0 . partial_cmp ( & other. 0 ) ,
540
- _ => {
541
-
542
-
543
- debug_assert_ne ! ( self , other , "Forgot a match arm?" ) ;
544
- None
545
- }
574
+
575
+
576
+ _ => unsafe {
577
+ match * self { Absolute ( .. ) | FontRelative ( .. ) | ViewportPercentage ( .. ) | ServoCharacterWidth ( .. ) => { } }
578
+ debug_unreachable ! ( "Forgot an arm in partial_cmp?" )
579
+ } ,
546
580
}
547
581
}
548
582
}
@@ -598,16 +632,22 @@ impl Mul<CSSFloat> for Length {
598
632
impl PartialOrd for FontRelativeLength {
599
633
fn partial_cmp ( & self , other : & Self ) -> Option < cmp:: Ordering > {
600
634
use self :: FontRelativeLength :: * ;
635
+
636
+ if std:: mem:: discriminant ( self ) != std:: mem:: discriminant ( other) {
637
+ return None ;
638
+ }
639
+
601
640
match ( self , other) {
602
641
( & Em ( ref one) , & Em ( ref other) ) => one. partial_cmp ( other) ,
603
642
( & Ex ( ref one) , & Ex ( ref other) ) => one. partial_cmp ( other) ,
604
643
( & Ch ( ref one) , & Ch ( ref other) ) => one. partial_cmp ( other) ,
605
644
( & Rem ( ref one) , & Rem ( ref other) ) => one. partial_cmp ( other) ,
606
- _ => {
607
-
608
- debug_assert_ne ! ( self , other, "Forgot a match arm?" ) ;
609
- None
610
- }
645
+
646
+
647
+ _ => unsafe {
648
+ match * self { Em ( ..) | Ex ( ..) | Ch ( ..) | Rem ( ..) => { } }
649
+ debug_unreachable ! ( "Forgot an arm in partial_cmp?" )
650
+ } ,
611
651
}
612
652
}
613
653
}
@@ -643,16 +683,22 @@ impl Mul<CSSFloat> for ViewportPercentageLength {
643
683
impl PartialOrd for ViewportPercentageLength {
644
684
fn partial_cmp ( & self , other : & Self ) -> Option < cmp:: Ordering > {
645
685
use self :: ViewportPercentageLength :: * ;
686
+
687
+ if std:: mem:: discriminant ( self ) != std:: mem:: discriminant ( other) {
688
+ return None ;
689
+ }
690
+
646
691
match ( self , other) {
647
692
( & Vw ( ref one) , & Vw ( ref other) ) => one. partial_cmp ( other) ,
648
693
( & Vh ( ref one) , & Vh ( ref other) ) => one. partial_cmp ( other) ,
649
694
( & Vmin ( ref one) , & Vmin ( ref other) ) => one. partial_cmp ( other) ,
650
695
( & Vmax ( ref one) , & Vmax ( ref other) ) => one. partial_cmp ( other) ,
651
- _ => {
652
-
653
- debug_assert_ne ! ( self , other, "Forgot a match arm?" ) ;
654
- None
655
- }
696
+
697
+
698
+ _ => unsafe {
699
+ match * self { Vw ( ..) | Vh ( ..) | Vmin ( ..) | Vmax ( ..) => { } }
700
+ debug_unreachable ! ( "Forgot an arm in partial_cmp?" )
701
+ } ,
656
702
}
657
703
}
658
704
}
0 commit comments