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