@@ -3961,6 +3961,24 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
3961
3961
if let Node :: Expr ( expr) = tcx. hir_node ( arg_hir_id)
3962
3962
&& let Some ( typeck_results) = & self . typeck_results
3963
3963
{
3964
+ if let hir:: Expr { kind : hir:: ExprKind :: MethodCall ( _, rcvr, _, _) , .. } = expr
3965
+ && let Some ( ty) = typeck_results. node_type_opt ( rcvr. hir_id )
3966
+ && let Some ( failed_pred) = failed_pred. to_opt_poly_trait_pred ( )
3967
+ && let pred = failed_pred. map_bound ( |pred| pred. with_self_ty ( tcx, ty) )
3968
+ && self . predicate_must_hold_modulo_regions ( & Obligation :: misc (
3969
+ tcx, expr. span , body_id, param_env, pred,
3970
+ ) )
3971
+ {
3972
+ err. span_suggestion_verbose (
3973
+ expr. span . with_lo ( rcvr. span . hi ( ) ) ,
3974
+ format ! (
3975
+ "consider removing this method call, as the receiver has type `{ty}` and \
3976
+ `{pred}` trivially holds",
3977
+ ) ,
3978
+ "" ,
3979
+ Applicability :: MaybeIncorrect ,
3980
+ ) ;
3981
+ }
3964
3982
if let hir:: Expr { kind : hir:: ExprKind :: Block ( block, _) , .. } = expr {
3965
3983
let inner_expr = expr. peel_blocks ( ) ;
3966
3984
let ty = typeck_results
@@ -4096,7 +4114,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
4096
4114
}
4097
4115
}
4098
4116
4099
- if let Node :: Expr ( expr) = tcx . hir_node ( call_hir_id ) {
4117
+ if let Node :: Expr ( expr) = call_node {
4100
4118
if let hir:: ExprKind :: Call ( hir:: Expr { span, .. } , _)
4101
4119
| hir:: ExprKind :: MethodCall (
4102
4120
hir:: PathSegment { ident : Ident { span, .. } , .. } ,
0 commit comments