@@ -760,7 +760,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
760760 ) ;
761761 ocx. resolve_regions_and_report_errors ( impl_m_def_id, & outlives_env) ?;
762762
763- let mut collected_tys = FxHashMap :: default ( ) ;
763+ let mut remapped_types = FxHashMap :: default ( ) ;
764764 for ( def_id, ( ty, args) ) in collected_types {
765765 match infcx. fully_resolve ( ( ty, args) ) {
766766 Ok ( ( ty, args) ) => {
@@ -810,19 +810,37 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
810810 Ok ( ty) => ty,
811811 Err ( guar) => Ty :: new_error ( tcx, guar) ,
812812 } ;
813- collected_tys . insert ( def_id, ty:: EarlyBinder :: bind ( ty) ) ;
813+ remapped_types . insert ( def_id, ty:: EarlyBinder :: bind ( ty) ) ;
814814 }
815815 Err ( err) => {
816816 let reported = tcx. sess . delay_span_bug (
817817 return_span,
818818 format ! ( "could not fully resolve: {ty} => {err:?}" ) ,
819819 ) ;
820- collected_tys . insert ( def_id, ty:: EarlyBinder :: bind ( Ty :: new_error ( tcx, reported) ) ) ;
820+ remapped_types . insert ( def_id, ty:: EarlyBinder :: bind ( Ty :: new_error ( tcx, reported) ) ) ;
821821 }
822822 }
823823 }
824824
825- Ok ( & * tcx. arena . alloc ( collected_tys) )
825+ // We may not collect all RPITITs that we see in the HIR for a trait signature
826+ // because an RPITIT was located within a missing item. Like if we have a sig
827+ // returning `-> Missing<impl Sized>`, that gets converted to `-> [type error]`,
828+ // and when walking through the signature we end up never collecting the def id
829+ // of the `impl Sized`. Insert that here, so we don't ICE later.
830+ for assoc_item in tcx. associated_types_for_impl_traits_in_associated_fn ( trait_m. def_id ) {
831+ if !remapped_types. contains_key ( assoc_item) {
832+ remapped_types. insert (
833+ * assoc_item,
834+ ty:: EarlyBinder :: bind ( Ty :: new_error_with_message (
835+ tcx,
836+ return_span,
837+ "missing synthetic item for RPITIT" ,
838+ ) ) ,
839+ ) ;
840+ }
841+ }
842+
843+ Ok ( & * tcx. arena . alloc ( remapped_types) )
826844}
827845
828846struct ImplTraitInTraitCollector < ' a , ' tcx > {
0 commit comments