@@ -426,11 +426,10 @@ impl<'tcx> Witness<'tcx> {
426
426
/// Option<!> we do not include Some(_) in the returned list of constructors.
427
427
fn all_constructors < ' a , ' tcx : ' a > ( cx : & mut MatchCheckCtxt < ' a , ' tcx > ,
428
428
pcx : PatternContext < ' tcx > )
429
- -> ( Vec < Constructor < ' tcx > > , bool )
429
+ -> Vec < Constructor < ' tcx > >
430
430
{
431
431
debug ! ( "all_constructors({:?})" , pcx. ty) ;
432
432
let exhaustive_integer_patterns = cx. tcx . features ( ) . exhaustive_integer_patterns ;
433
- let mut value_constructors = false ;
434
433
let ctors = match pcx. ty . sty {
435
434
ty:: TyBool => {
436
435
[ true , false ] . iter ( ) . map ( |& b| {
@@ -461,7 +460,6 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
461
460
. collect ( )
462
461
}
463
462
ty:: TyChar if exhaustive_integer_patterns => {
464
- value_constructors = true ;
465
463
let endpoint = |c : char | {
466
464
let ty = ty:: ParamEnv :: empty ( ) . and ( cx. tcx . types . char ) ;
467
465
ty:: Const :: from_bits ( cx. tcx , c as u128 , ty)
@@ -473,7 +471,6 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
473
471
]
474
472
}
475
473
ty:: TyInt ( ity) if exhaustive_integer_patterns => {
476
- value_constructors = true ;
477
474
// FIXME(49937): refactor these bit manipulations into interpret.
478
475
let bits = Integer :: from_attr ( cx. tcx , SignedInt ( ity) ) . size ( ) . bits ( ) as u128 ;
479
476
let min = 1u128 << ( bits - 1 ) ;
@@ -484,7 +481,6 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
484
481
RangeEnd :: Included ) ]
485
482
}
486
483
ty:: TyUint ( uty) if exhaustive_integer_patterns => {
487
- value_constructors = true ;
488
484
// FIXME(49937): refactor these bit manipulations into interpret.
489
485
let bits = Integer :: from_attr ( cx. tcx , UnsignedInt ( uty) ) . size ( ) . bits ( ) as u128 ;
490
486
let max = !0u128 >> ( 128 - bits) ;
@@ -501,7 +497,7 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
501
497
}
502
498
}
503
499
} ;
504
- ( ctors, value_constructors )
500
+ ctors
505
501
}
506
502
507
503
fn max_slice_length < ' p , ' a : ' p , ' tcx : ' a , I > (
@@ -810,22 +806,23 @@ pub fn is_useful<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
810
806
debug ! ( "used_ctors = {:#?}" , used_ctors) ;
811
807
// `all_ctors` are all the constructors for the given type, which
812
808
// should all be represented (or caught with the wild pattern `_`).
813
- // `value_constructors` is true if we may exhaustively consider all
814
- // the possible values (e.g. integers) of a type as its constructors.
815
- let ( all_ctors, value_constructors) = all_constructors ( cx, pcx) ;
809
+ let all_ctors = all_constructors ( cx, pcx) ;
816
810
debug ! ( "all_ctors = {:#?}" , all_ctors) ;
817
811
812
+ // The only constructor patterns for which it is valid to
813
+ // treat the values as constructors are ranges (see
814
+ // `all_constructors` for details).
815
+ let exhaustive_integer_patterns = cx. tcx . features ( ) . exhaustive_integer_patterns ;
816
+ let consider_value_constructors = exhaustive_integer_patterns
817
+ && all_ctors. iter ( ) . all ( |ctor| match ctor {
818
+ ConstantRange ( ..) => true ,
819
+ _ => false ,
820
+ } ) ;
821
+
818
822
// `missing_ctors` are those that should have appeared
819
823
// as patterns in the `match` expression, but did not.
820
824
let mut missing_ctors = vec ! [ ] ;
821
825
for req_ctor in & all_ctors {
822
- // The only constructor patterns for which it is valid to
823
- // treat the values as constructors are ranges (see
824
- // `all_constructors` for details).
825
- let consider_value_constructors = value_constructors && match req_ctor {
826
- ConstantRange ( ..) => true ,
827
- _ => false ,
828
- } ;
829
826
if consider_value_constructors {
830
827
let mut refined_ctors = vec ! [ req_ctor. clone( ) ] ;
831
828
for used_ctor in & used_ctors {
@@ -886,7 +883,7 @@ pub fn is_useful<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
886
883
let is_non_exhaustive = is_privately_empty || is_declared_nonexhaustive;
887
884
888
885
if missing_ctors. is_empty ( ) && !is_non_exhaustive {
889
- if value_constructors {
886
+ if consider_value_constructors {
890
887
// If we've successfully matched every value
891
888
// of the type, then we're done.
892
889
NotUseful
@@ -962,7 +959,7 @@ pub fn is_useful<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
962
959
witness
963
960
} ) . collect ( )
964
961
} else {
965
- if value_constructors {
962
+ if consider_value_constructors {
966
963
// If we've been trying to exhaustively match
967
964
// over the domain of values for a type,
968
965
// then we can provide better diagnostics
0 commit comments