@@ -760,7 +760,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
760
760
) ;
761
761
ocx. resolve_regions_and_report_errors ( impl_m_def_id, & outlives_env) ?;
762
762
763
- let mut collected_tys = FxHashMap :: default ( ) ;
763
+ let mut remapped_types = FxHashMap :: default ( ) ;
764
764
for ( def_id, ( ty, args) ) in collected_types {
765
765
match infcx. fully_resolve ( ( ty, args) ) {
766
766
Ok ( ( ty, args) ) => {
@@ -810,19 +810,37 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
810
810
Ok ( ty) => ty,
811
811
Err ( guar) => Ty :: new_error ( tcx, guar) ,
812
812
} ;
813
- collected_tys . insert ( def_id, ty:: EarlyBinder :: bind ( ty) ) ;
813
+ remapped_types . insert ( def_id, ty:: EarlyBinder :: bind ( ty) ) ;
814
814
}
815
815
Err ( err) => {
816
816
let reported = tcx. sess . delay_span_bug (
817
817
return_span,
818
818
format ! ( "could not fully resolve: {ty} => {err:?}" ) ,
819
819
) ;
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) ) ) ;
821
821
}
822
822
}
823
823
}
824
824
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) )
826
844
}
827
845
828
846
struct ImplTraitInTraitCollector < ' a , ' tcx > {
0 commit comments