@@ -11,7 +11,6 @@ use rustc_data_structures::intern::{Interned, WithStableHash};
1111use  rustc_hir:: def_id:: DefId ; 
1212use  rustc_macros:: HashStable ; 
1313use  rustc_serialize:: { self ,  Decodable ,  Encodable } ; 
14- use  rustc_span:: DUMMY_SP ; 
1514use  smallvec:: SmallVec ; 
1615
1716use  core:: intrinsics; 
@@ -525,6 +524,7 @@ struct SubstFolder<'a, 'tcx> {
525524} 
526525
527526impl < ' a ,  ' tcx >  TypeFolder < ' tcx >  for  SubstFolder < ' a ,  ' tcx >  { 
527+     #[ inline]  
528528    fn  tcx < ' b > ( & ' b  self )  -> TyCtxt < ' tcx >  { 
529529        self . tcx 
530530    } 
@@ -540,6 +540,16 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
540540    } 
541541
542542    fn  fold_region ( & mut  self ,  r :  ty:: Region < ' tcx > )  -> ty:: Region < ' tcx >  { 
543+         #[ cold]  
544+         #[ inline( never) ]  
545+         fn  region_param_out_of_range ( data :  ty:: EarlyBoundRegion )  -> ! { 
546+             bug ! ( 
547+                 "Region parameter out of range when substituting in region {} (index={})" , 
548+                 data. name, 
549+                 data. index
550+             ) 
551+         } 
552+ 
543553        // Note: This routine only handles regions that are bound on 
544554        // type declarations and other outer declarations, not those 
545555        // bound in *fn types*. Region substitution of the bound 
@@ -550,14 +560,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
550560                let  rk = self . substs . get ( data. index  as  usize ) . map ( |k| k. unpack ( ) ) ; 
551561                match  rk { 
552562                    Some ( GenericArgKind :: Lifetime ( lt) )  => self . shift_region_through_binders ( lt) , 
553-                     _ => { 
554-                         let  msg = format ! ( 
555-                             "Region parameter out of range \  
556-                               when substituting in region {} (index={})", 
557-                             data. name,  data. index
558-                         ) ; 
559-                         span_bug ! ( DUMMY_SP ,  "{}" ,  msg) ; 
560-                     } 
563+                     _ => region_param_out_of_range ( data) , 
561564                } 
562565            } 
563566            _ => r, 
@@ -595,67 +598,80 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
595598        let  opt_ty = self . substs . get ( p. index  as  usize ) . map ( |k| k. unpack ( ) ) ; 
596599        let  ty = match  opt_ty { 
597600            Some ( GenericArgKind :: Type ( ty) )  => ty, 
598-             Some ( kind)  => { 
599-                 span_bug ! ( 
600-                     DUMMY_SP , 
601-                     "expected type for `{:?}` ({:?}/{}) but found {:?} \  
602-                       when substituting, substs={:?}", 
603-                     p, 
604-                     source_ty, 
605-                     p. index, 
606-                     kind, 
607-                     self . substs, 
608-                 ) ; 
609-             } 
610-             None  => { 
611-                 span_bug ! ( 
612-                     DUMMY_SP , 
613-                     "type parameter `{:?}` ({:?}/{}) out of range \  
614-                       when substituting, substs={:?}", 
615-                     p, 
616-                     source_ty, 
617-                     p. index, 
618-                     self . substs, 
619-                 ) ; 
620-             } 
601+             Some ( kind)  => self . type_param_expected ( p,  source_ty,  kind) , 
602+             None  => self . type_param_out_of_range ( p,  source_ty) , 
621603        } ; 
622604
623605        self . shift_vars_through_binders ( ty) 
624606    } 
625607
608+     #[ cold]  
609+     #[ inline( never) ]  
610+     fn  type_param_expected ( & self ,  p :  ty:: ParamTy ,  ty :  Ty < ' tcx > ,  kind :  GenericArgKind < ' tcx > )  -> ! { 
611+         bug ! ( 
612+             "expected type for `{:?}` ({:?}/{}) but found {:?} when substituting, substs={:?}" , 
613+             p, 
614+             ty, 
615+             p. index, 
616+             kind, 
617+             self . substs, 
618+         ) 
619+     } 
620+ 
621+     #[ cold]  
622+     #[ inline( never) ]  
623+     fn  type_param_out_of_range ( & self ,  p :  ty:: ParamTy ,  ty :  Ty < ' tcx > )  -> ! { 
624+         bug ! ( 
625+             "type parameter `{:?}` ({:?}/{}) out of range when substituting, substs={:?}" , 
626+             p, 
627+             ty, 
628+             p. index, 
629+             self . substs, 
630+         ) 
631+     } 
632+ 
626633    fn  const_for_param ( & self ,  p :  ParamConst ,  source_ct :  ty:: Const < ' tcx > )  -> ty:: Const < ' tcx >  { 
627634        // Look up the const in the substitutions. It really should be in there. 
628635        let  opt_ct = self . substs . get ( p. index  as  usize ) . map ( |k| k. unpack ( ) ) ; 
629636        let  ct = match  opt_ct { 
630637            Some ( GenericArgKind :: Const ( ct) )  => ct, 
631-             Some ( kind)  => { 
632-                 span_bug ! ( 
633-                     DUMMY_SP , 
634-                     "expected const for `{:?}` ({:?}/{}) but found {:?} \  
635-                       when substituting substs={:?}", 
636-                     p, 
637-                     source_ct, 
638-                     p. index, 
639-                     kind, 
640-                     self . substs, 
641-                 ) ; 
642-             } 
643-             None  => { 
644-                 span_bug ! ( 
645-                     DUMMY_SP , 
646-                     "const parameter `{:?}` ({:?}/{}) out of range \  
647-                       when substituting substs={:?}", 
648-                     p, 
649-                     source_ct, 
650-                     p. index, 
651-                     self . substs, 
652-                 ) ; 
653-             } 
638+             Some ( kind)  => self . const_param_expected ( p,  source_ct,  kind) , 
639+             None  => self . const_param_out_of_range ( p,  source_ct) , 
654640        } ; 
655641
656642        self . shift_vars_through_binders ( ct) 
657643    } 
658644
645+     #[ cold]  
646+     #[ inline( never) ]  
647+     fn  const_param_expected ( 
648+         & self , 
649+         p :  ty:: ParamConst , 
650+         ct :  ty:: Const < ' tcx > , 
651+         kind :  GenericArgKind < ' tcx > , 
652+     )  -> ! { 
653+         bug ! ( 
654+             "expected const for `{:?}` ({:?}/{}) but found {:?} when substituting substs={:?}" , 
655+             p, 
656+             ct, 
657+             p. index, 
658+             kind, 
659+             self . substs, 
660+         ) 
661+     } 
662+ 
663+     #[ cold]  
664+     #[ inline( never) ]  
665+     fn  const_param_out_of_range ( & self ,  p :  ty:: ParamConst ,  ct :  ty:: Const < ' tcx > )  -> ! { 
666+         bug ! ( 
667+             "const parameter `{:?}` ({:?}/{}) out of range when substituting substs={:?}" , 
668+             p, 
669+             ct, 
670+             p. index, 
671+             self . substs, 
672+         ) 
673+     } 
674+ 
659675    /// It is sometimes necessary to adjust the De Bruijn indices during substitution. This occurs 
660676     /// when we are substituting a type with escaping bound vars into a context where we have 
661677     /// passed through binders. That's quite a mouthful. Let's see an example: 
0 commit comments