@@ -29,6 +29,18 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
2929 let trait_m_to_impl_m_args = impl_m_args. rebase_onto ( tcx, impl_def_id, impl_trait_ref. args ) ;
3030 let bound_trait_m_sig = tcx. fn_sig ( trait_m. def_id ) . instantiate ( tcx, trait_m_to_impl_m_args) ;
3131 let trait_m_sig = tcx. liberate_late_bound_regions ( impl_m. def_id , bound_trait_m_sig) ;
32+ // replace the self type of the trait ref with `Self` so that diagnostics render better.
33+ let trait_m_sig_with_self_for_diag = tcx. liberate_late_bound_regions (
34+ impl_m. def_id ,
35+ tcx. fn_sig ( trait_m. def_id ) . instantiate (
36+ tcx,
37+ tcx. mk_args_from_iter (
38+ [ tcx. types . self_param . into ( ) ]
39+ . into_iter ( )
40+ . chain ( trait_m_to_impl_m_args. iter ( ) . skip ( 1 ) ) ,
41+ ) ,
42+ ) ,
43+ ) ;
3244
3345 let Ok ( hidden_tys) = tcx. collect_return_position_impl_trait_in_trait_tys ( impl_m. def_id ) else {
3446 // Error already emitted, no need to delay another.
@@ -51,7 +63,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
5163 let ty:: Alias ( ty:: Opaque , impl_opaque) = * hidden_ty. kind ( ) else {
5264 report_mismatched_rpitit_signature (
5365 tcx,
54- trait_m_sig ,
66+ trait_m_sig_with_self_for_diag ,
5567 trait_m. def_id ,
5668 impl_m. def_id ,
5769 None ,
@@ -70,7 +82,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
7082 } ) {
7183 report_mismatched_rpitit_signature (
7284 tcx,
73- trait_m_sig ,
85+ trait_m_sig_with_self_for_diag ,
7486 trait_m. def_id ,
7587 impl_m. def_id ,
7688 None ,
@@ -163,7 +175,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
163175 if !trait_bounds. contains ( & clause) {
164176 report_mismatched_rpitit_signature (
165177 tcx,
166- trait_m_sig ,
178+ trait_m_sig_with_self_for_diag ,
167179 trait_m. def_id ,
168180 impl_m. def_id ,
169181 Some ( span) ,
0 commit comments