@@ -9,7 +9,8 @@ use rustc_middle::ty::print::with_forced_trimmed_paths;
9
9
use rustc_middle:: ty:: subst:: InternalSubsts ;
10
10
use rustc_middle:: ty:: util:: IntTypeExt ;
11
11
use rustc_middle:: ty:: {
12
- self , IsSuggestable , Ty , TyCtxt , TypeFolder , TypeSuperFoldable , TypeVisitableExt ,
12
+ self , ImplTraitInTraitData , IsSuggestable , Ty , TyCtxt , TypeFolder , TypeSuperFoldable ,
13
+ TypeVisitableExt ,
13
14
} ;
14
15
use rustc_span:: symbol:: Ident ;
15
16
use rustc_span:: { Span , DUMMY_SP } ;
@@ -244,6 +245,24 @@ fn get_path_containing_arg_in_pat<'hir>(
244
245
}
245
246
246
247
pub ( super ) fn type_of ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> ty:: EarlyBinder < Ty < ' _ > > {
248
+ // If we are computing `type_of` the synthesized associated type for an RPITIT in the impl
249
+ // side, use `collect_return_position_impl_trait_in_trait_tys` to infer the value of the
250
+ // associated type in the impl.
251
+ if let Some ( ImplTraitInTraitData :: Impl { fn_def_id, .. } ) = tcx. opt_rpitit_info ( def_id) {
252
+ match tcx. collect_return_position_impl_trait_in_trait_tys ( fn_def_id) {
253
+ Ok ( map) => {
254
+ let assoc_item = tcx. associated_item ( def_id) ;
255
+ return ty:: EarlyBinder ( map[ & assoc_item. trait_item_def_id . unwrap ( ) ] ) ;
256
+ }
257
+ Err ( _) => {
258
+ return ty:: EarlyBinder ( tcx. ty_error_with_message (
259
+ DUMMY_SP ,
260
+ "Could not collect return position impl trait in trait tys" ,
261
+ ) ) ;
262
+ }
263
+ }
264
+ }
265
+
247
266
let def_id = def_id. expect_local ( ) ;
248
267
use rustc_hir:: * ;
249
268
0 commit comments