@@ -658,6 +658,45 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
658658 // ```
659659 }
660660 }
661+
662+ fn add_wf_preds_for_pat_ty ( & mut self , base_ty : Ty < ' tcx > , pat : ty:: Pattern < ' tcx > ) {
663+ let tcx = self . tcx ( ) ;
664+ match * pat {
665+ ty:: PatternKind :: Range { start, end } => {
666+ let mut check = |c| {
667+ let cause = self . cause ( ObligationCauseCode :: Misc ) ;
668+ self . out . push ( traits:: Obligation :: with_depth (
669+ tcx,
670+ cause. clone ( ) ,
671+ self . recursion_depth ,
672+ self . param_env ,
673+ ty:: Binder :: dummy ( ty:: PredicateKind :: Clause (
674+ ty:: ClauseKind :: ConstArgHasType ( c, base_ty) ,
675+ ) ) ,
676+ ) ) ;
677+ if !tcx. features ( ) . generic_pattern_types ( ) {
678+ if c. has_param ( ) {
679+ if self . span . is_dummy ( ) {
680+ self . tcx ( )
681+ . dcx ( )
682+ . delayed_bug ( "feature error should be reported elsewhere, too" ) ;
683+ } else {
684+ feature_err (
685+ & self . tcx ( ) . sess ,
686+ sym:: generic_pattern_types,
687+ self . span ,
688+ "wraparound pattern type ranges cause monomorphization time errors" ,
689+ )
690+ . emit ( ) ;
691+ }
692+ }
693+ }
694+ } ;
695+ check ( start) ;
696+ check ( end) ;
697+ }
698+ }
699+ }
661700}
662701
663702impl < ' a , ' tcx > TypeVisitor < TyCtxt < ' tcx > > for WfPredicates < ' a , ' tcx > {
@@ -710,43 +749,9 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
710749 ) ) ;
711750 }
712751
713- ty:: Pat ( subty, pat) => {
714- self . require_sized ( subty, ObligationCauseCode :: Misc ) ;
715- match * pat {
716- ty:: PatternKind :: Range { start, end } => {
717- let mut check = |c| {
718- let cause = self . cause ( ObligationCauseCode :: Misc ) ;
719- self . out . push ( traits:: Obligation :: with_depth (
720- tcx,
721- cause. clone ( ) ,
722- self . recursion_depth ,
723- self . param_env ,
724- ty:: Binder :: dummy ( ty:: PredicateKind :: Clause (
725- ty:: ClauseKind :: ConstArgHasType ( c, subty) ,
726- ) ) ,
727- ) ) ;
728- if !tcx. features ( ) . generic_pattern_types ( ) {
729- if c. has_param ( ) {
730- if self . span . is_dummy ( ) {
731- self . tcx ( ) . dcx ( ) . delayed_bug (
732- "feature error should be reported elsewhere, too" ,
733- ) ;
734- } else {
735- feature_err (
736- & self . tcx ( ) . sess ,
737- sym:: generic_pattern_types,
738- self . span ,
739- "wraparound pattern type ranges cause monomorphization time errors" ,
740- )
741- . emit ( ) ;
742- }
743- }
744- }
745- } ;
746- check ( start) ;
747- check ( end) ;
748- }
749- }
752+ ty:: Pat ( base_ty, pat) => {
753+ self . require_sized ( base_ty, ObligationCauseCode :: Misc ) ;
754+ self . add_wf_preds_for_pat_ty ( base_ty, pat) ;
750755 }
751756
752757 ty:: Tuple ( tys) => {
0 commit comments