@@ -26,6 +26,7 @@ struct ConfirmContext<'a, 'tcx> {
26
26
span : Span ,
27
27
self_expr : & ' tcx hir:: Expr < ' tcx > ,
28
28
call_expr : & ' tcx hir:: Expr < ' tcx > ,
29
+ skip_record_for_diagnostics : bool ,
29
30
}
30
31
31
32
impl < ' a , ' tcx > Deref for ConfirmContext < ' a , ' tcx > {
@@ -59,6 +60,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
59
60
let mut confirm_cx = ConfirmContext :: new ( self , span, self_expr, call_expr) ;
60
61
confirm_cx. confirm ( unadjusted_self_ty, pick, segment)
61
62
}
63
+
64
+ pub fn confirm_method_for_diagnostic (
65
+ & self ,
66
+ span : Span ,
67
+ self_expr : & ' tcx hir:: Expr < ' tcx > ,
68
+ call_expr : & ' tcx hir:: Expr < ' tcx > ,
69
+ unadjusted_self_ty : Ty < ' tcx > ,
70
+ pick : & probe:: Pick < ' tcx > ,
71
+ segment : & hir:: PathSegment < ' _ > ,
72
+ ) -> ConfirmResult < ' tcx > {
73
+ let mut confirm_cx = ConfirmContext :: new ( self , span, self_expr, call_expr) ;
74
+ confirm_cx. skip_record_for_diagnostics = true ;
75
+ confirm_cx. confirm ( unadjusted_self_ty, pick, segment)
76
+ }
62
77
}
63
78
64
79
impl < ' a , ' tcx > ConfirmContext < ' a , ' tcx > {
@@ -68,7 +83,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
68
83
self_expr : & ' tcx hir:: Expr < ' tcx > ,
69
84
call_expr : & ' tcx hir:: Expr < ' tcx > ,
70
85
) -> ConfirmContext < ' a , ' tcx > {
71
- ConfirmContext { fcx, span, self_expr, call_expr }
86
+ ConfirmContext { fcx, span, self_expr, call_expr, skip_record_for_diagnostics : false }
72
87
}
73
88
74
89
fn confirm (
@@ -219,7 +234,9 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
219
234
self . register_predicates ( autoderef. into_obligations ( ) ) ;
220
235
221
236
// Write out the final adjustments.
222
- self . apply_adjustments ( self . self_expr , adjustments) ;
237
+ if !self . skip_record_for_diagnostics {
238
+ self . apply_adjustments ( self . self_expr , adjustments) ;
239
+ }
223
240
224
241
target
225
242
}
@@ -453,7 +470,10 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
453
470
} ) ;
454
471
455
472
debug ! ( "instantiate_method_substs: user_type_annotation={:?}" , user_type_annotation) ;
456
- self . fcx . write_user_type_annotation ( self . call_expr . hir_id , user_type_annotation) ;
473
+
474
+ if !self . skip_record_for_diagnostics {
475
+ self . fcx . write_user_type_annotation ( self . call_expr . hir_id , user_type_annotation) ;
476
+ }
457
477
}
458
478
459
479
self . normalize ( self . span , substs)
0 commit comments