@@ -756,7 +756,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
756
756
) ;
757
757
ocx. resolve_regions_and_report_errors ( impl_m_def_id, & outlives_env) ?;
758
758
759
- let mut collected_tys = FxHashMap :: default ( ) ;
759
+ let mut remapped_types = FxHashMap :: default ( ) ;
760
760
for ( def_id, ( ty, args) ) in collected_types {
761
761
match infcx. fully_resolve ( ( ty, args) ) {
762
762
Ok ( ( ty, args) ) => {
@@ -806,19 +806,37 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
806
806
Ok ( ty) => ty,
807
807
Err ( guar) => Ty :: new_error ( tcx, guar) ,
808
808
} ;
809
- collected_tys . insert ( def_id, ty:: EarlyBinder :: bind ( ty) ) ;
809
+ remapped_types . insert ( def_id, ty:: EarlyBinder :: bind ( ty) ) ;
810
810
}
811
811
Err ( err) => {
812
812
let reported = tcx. sess . delay_span_bug (
813
813
return_span,
814
814
format ! ( "could not fully resolve: {ty} => {err:?}" ) ,
815
815
) ;
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) ) ) ;
817
817
}
818
818
}
819
819
}
820
820
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) )
822
840
}
823
841
824
842
struct ImplTraitInTraitCollector < ' a , ' tcx > {
0 commit comments