@@ -518,8 +518,7 @@ fn enter_default<'a, 'b>(
518
518
dm : & DefMap ,
519
519
m : & ' a [ Match < ' a , ' b > ] ,
520
520
col : uint ,
521
- val : ValueRef ,
522
- chk : & FailureHandler )
521
+ val : ValueRef )
523
522
-> Vec < Match < ' a , ' b > > {
524
523
debug ! ( "enter_default(bcx={}, m={}, col={}, val={})" ,
525
524
bcx. to_str( ) ,
@@ -529,35 +528,13 @@ fn enter_default<'a, 'b>(
529
528
let _indenter = indenter ( ) ;
530
529
531
530
// Collect all of the matches that can match against anything.
532
- let matches = enter_match ( bcx, dm, m, col, val, |p| {
531
+ enter_match ( bcx, dm, m, col, val, |p| {
533
532
match p. node {
534
533
ast:: PatWild | ast:: PatWildMulti => Some ( Vec :: new ( ) ) ,
535
534
ast:: PatIdent ( _, _, None ) if pat_is_binding ( dm, & * p) => Some ( Vec :: new ( ) ) ,
536
535
_ => None
537
536
}
538
- } ) ;
539
-
540
- // Ok, now, this is pretty subtle. A "default" match is a match
541
- // that needs to be considered if none of the actual checks on the
542
- // value being considered succeed. The subtlety lies in that sometimes
543
- // identifier/wildcard matches are *not* default matches. Consider:
544
- // "match x { _ if something => foo, true => bar, false => baz }".
545
- // There is a wildcard match, but it is *not* a default case. The boolean
546
- // case on the value being considered is exhaustive. If the case is
547
- // exhaustive, then there are no defaults.
548
- //
549
- // We detect whether the case is exhaustive in the following
550
- // somewhat kludgy way: if the last wildcard/binding match has a
551
- // guard, then by non-redundancy, we know that there aren't any
552
- // non guarded matches, and thus by exhaustiveness, we know that
553
- // we don't need any default cases. If the check *isn't* nonexhaustive
554
- // (because chk is Some), then we need the defaults anyways.
555
- let is_exhaustive = match matches. last ( ) {
556
- Some ( m) if m. data . arm . guard . is_some ( ) && chk. is_infallible ( ) => true ,
557
- _ => false
558
- } ;
559
-
560
- if is_exhaustive { Vec :: new ( ) } else { matches }
537
+ } )
561
538
}
562
539
563
540
// <pcwalton> nmatsakis: what does enter_opt do?
@@ -1448,15 +1425,12 @@ fn compile_submatch<'a, 'b>(
1448
1425
m. repr( bcx. tcx( ) ) ,
1449
1426
vec_map_to_str( vals, |v| bcx. val_to_str( * v) ) ) ;
1450
1427
let _indenter = indenter ( ) ;
1451
-
1452
- /*
1453
- For an empty match, a fall-through case must exist
1454
- */
1455
- assert ! ( ( m. len( ) > 0 u || chk. is_fallible( ) ) ) ;
1456
1428
let _icx = push_ctxt ( "match::compile_submatch" ) ;
1457
1429
let mut bcx = bcx;
1458
1430
if m. len ( ) == 0 u {
1459
- Br ( bcx, chk. handle_fail ( ) ) ;
1431
+ if chk. is_fallible ( ) {
1432
+ Br ( bcx, chk. handle_fail ( ) ) ;
1433
+ }
1460
1434
return ;
1461
1435
}
1462
1436
if m[ 0 ] . pats . len ( ) == 0 u {
@@ -1658,7 +1632,7 @@ fn compile_submatch_continue<'a, 'b>(
1658
1632
C_int ( ccx, 0 ) // Placeholder for when not using a switch
1659
1633
} ;
1660
1634
1661
- let defaults = enter_default ( else_cx, dm, m, col, val, chk ) ;
1635
+ let defaults = enter_default ( else_cx, dm, m, col, val) ;
1662
1636
let exhaustive = chk. is_infallible ( ) && defaults. len ( ) == 0 u;
1663
1637
let len = opts. len ( ) ;
1664
1638
@@ -1947,18 +1921,14 @@ fn trans_match_inner<'a>(scope_cx: &'a Block<'a>,
1947
1921
1948
1922
// `compile_submatch` works one column of arm patterns a time and
1949
1923
// then peels that column off. So as we progress, it may become
1950
- // impossible to know whether we have a genuine default arm, i.e.
1924
+ // impossible to tell whether we have a genuine default arm, i.e.
1951
1925
// `_ => foo` or not. Sometimes it is important to know that in order
1952
1926
// to decide whether moving on to the next condition or falling back
1953
1927
// to the default arm.
1954
- let has_default = arms. len ( ) > 0 && {
1955
- let ref pats = arms. last ( ) . unwrap ( ) . pats ;
1956
-
1957
- pats. len ( ) == 1
1958
- && match pats. last ( ) . unwrap ( ) . node {
1959
- ast:: PatWild => true , _ => false
1960
- }
1961
- } ;
1928
+ let has_default = arms. last ( ) . map_or ( false , |arm| {
1929
+ arm. pats . len ( ) == 1
1930
+ && arm. pats . last ( ) . unwrap ( ) . node == ast:: PatWild
1931
+ } ) ;
1962
1932
1963
1933
compile_submatch ( bcx, matches. as_slice ( ) , [ discr_datum. val ] , & chk, has_default) ;
1964
1934
0 commit comments