@@ -29,6 +29,18 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
29
29
let trait_m_to_impl_m_args = impl_m_args. rebase_onto ( tcx, impl_def_id, impl_trait_ref. args ) ;
30
30
let bound_trait_m_sig = tcx. fn_sig ( trait_m. def_id ) . instantiate ( tcx, trait_m_to_impl_m_args) ;
31
31
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
+ ) ;
32
44
33
45
let Ok ( hidden_tys) = tcx. collect_return_position_impl_trait_in_trait_tys ( impl_m. def_id ) else {
34
46
// Error already emitted, no need to delay another.
@@ -51,7 +63,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
51
63
let ty:: Alias ( ty:: Opaque , impl_opaque) = * hidden_ty. kind ( ) else {
52
64
report_mismatched_rpitit_signature (
53
65
tcx,
54
- trait_m_sig ,
66
+ trait_m_sig_with_self_for_diag ,
55
67
trait_m. def_id ,
56
68
impl_m. def_id ,
57
69
None ,
@@ -70,7 +82,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
70
82
} ) {
71
83
report_mismatched_rpitit_signature (
72
84
tcx,
73
- trait_m_sig ,
85
+ trait_m_sig_with_self_for_diag ,
74
86
trait_m. def_id ,
75
87
impl_m. def_id ,
76
88
None ,
@@ -163,7 +175,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
163
175
if !trait_bounds. contains ( & clause) {
164
176
report_mismatched_rpitit_signature (
165
177
tcx,
166
- trait_m_sig ,
178
+ trait_m_sig_with_self_for_diag ,
167
179
trait_m. def_id ,
168
180
impl_m. def_id ,
169
181
Some ( span) ,
0 commit comments