@@ -295,12 +295,26 @@ pub(super) fn compare_predicates_and_trait_impl_trait_tys<'tcx>(
295
295
// type would be more appropriate. In other places we have a `Vec<Span>`
296
296
// corresponding to their `Vec<Predicate>`, but we don't have that here.
297
297
// Fixing this would improve the output of test `issue-83765.rs`.
298
- let sub_result = infcx
298
+ let mut result = infcx
299
299
. at ( & cause, param_env)
300
300
. sup ( trait_fty, impl_fty)
301
301
. map ( |infer_ok| ocx. register_infer_ok_obligations ( infer_ok) ) ;
302
302
303
- if let Err ( terr) = sub_result {
303
+ // HACK(RPITIT): #101614. When we are trying to infer the hidden types for
304
+ // RPITITs, we need to equate the output tys instead of just subtyping. If
305
+ // we just use `sup` above, we'll end up `&'static str <: _#1t`, which causes
306
+ // us to infer `_#1t = #'_#2r str`, where `'_#2r` is unconstrained, which gets
307
+ // fixed up to `ReEmpty`, and which is certainly not what we want.
308
+ if trait_fty. has_infer_types ( ) {
309
+ result = result. and_then ( |( ) | {
310
+ infcx
311
+ . at ( & cause, param_env)
312
+ . eq ( trait_sig. output ( ) , impl_sig. output ( ) )
313
+ . map ( |infer_ok| ocx. register_infer_ok_obligations ( infer_ok) )
314
+ } ) ;
315
+ }
316
+
317
+ if let Err ( terr) = result {
304
318
debug ! ( "sub_types failed: impl ty {:?}, trait ty {:?}" , impl_fty, trait_fty) ;
305
319
306
320
let ( impl_err_span, trait_err_span) =
@@ -445,6 +459,7 @@ pub(super) fn compare_predicates_and_trait_impl_trait_tys<'tcx>(
445
459
region
446
460
}
447
461
} ) ;
462
+ debug ! ( %ty) ;
448
463
collected_tys. insert ( def_id, ty) ;
449
464
}
450
465
Err ( err) => {
0 commit comments