File tree Expand file tree Collapse file tree 3 files changed +32
-13
lines changed
compiler/rustc_middle/src/ty Expand file tree Collapse file tree 3 files changed +32
-13
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,20 @@ impl GenericParamDef {
101101 _ => None ,
102102 }
103103 }
104+
105+ pub fn to_error < ' tcx > (
106+ & self ,
107+ tcx : TyCtxt < ' tcx > ,
108+ preceding_substs : & [ ty:: GenericArg < ' tcx > ] ,
109+ ) -> ty:: GenericArg < ' tcx > {
110+ match & self . kind {
111+ ty:: GenericParamDefKind :: Lifetime => tcx. lifetimes . re_static . into ( ) ,
112+ ty:: GenericParamDefKind :: Type { .. } => tcx. ty_error ( ) . into ( ) ,
113+ ty:: GenericParamDefKind :: Const { .. } => {
114+ tcx. const_error ( tcx. bound_type_of ( self . def_id ) . subst ( tcx, preceding_substs) ) . into ( )
115+ }
116+ }
117+ }
104118}
105119
106120#[ derive( Default ) ]
Original file line number Diff line number Diff line change @@ -728,19 +728,8 @@ impl<'tcx> PolyExistentialPredicate<'tcx> {
728728 } else {
729729 // If this is an ill-formed auto trait, then synthesize
730730 // new error substs for the missing generics.
731- let err_substs = ty:: InternalSubsts :: for_item ( tcx, did, |def, substs| {
732- if def. index == 0 {
733- self_ty. into ( )
734- } else {
735- match & def. kind {
736- ty:: GenericParamDefKind :: Lifetime => tcx. lifetimes . re_static . into ( ) ,
737- ty:: GenericParamDefKind :: Type { .. } => tcx. ty_error ( ) . into ( ) ,
738- ty:: GenericParamDefKind :: Const { .. } => tcx
739- . const_error ( tcx. bound_type_of ( def. def_id ) . subst ( tcx, substs) )
740- . into ( ) ,
741- }
742- }
743- } ) ;
731+ let err_substs =
732+ ty:: InternalSubsts :: extend_with_error ( tcx, did, & [ self_ty. into ( ) ] ) ;
744733 tcx. mk_trait_ref ( did, err_substs)
745734 } ;
746735 self . rebind ( trait_ref) . without_const ( ) . to_predicate ( tcx)
Original file line number Diff line number Diff line change @@ -352,6 +352,22 @@ impl<'tcx> InternalSubsts<'tcx> {
352352 }
353353 }
354354
355+ // Extend an `original_substs` list to the full number of substs expected by `def_id`,
356+ // filling in the missing parameters with error ty/ct or 'static regions.
357+ pub fn extend_with_error (
358+ tcx : TyCtxt < ' tcx > ,
359+ def_id : DefId ,
360+ original_substs : & [ GenericArg < ' tcx > ] ,
361+ ) -> SubstsRef < ' tcx > {
362+ ty:: InternalSubsts :: for_item ( tcx, def_id, |def, substs| {
363+ if let Some ( subst) = original_substs. get ( def. index as usize ) {
364+ * subst
365+ } else {
366+ def. to_error ( tcx, substs)
367+ }
368+ } )
369+ }
370+
355371 #[ inline]
356372 pub fn types ( & ' tcx self ) -> impl DoubleEndedIterator < Item = Ty < ' tcx > > + ' tcx {
357373 self . iter ( )
You can’t perform that action at this time.
0 commit comments