@@ -3689,6 +3689,24 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
3689
3689
if let Node :: Expr ( expr) = tcx. hir_node ( arg_hir_id)
3690
3690
&& let Some ( typeck_results) = & self . typeck_results
3691
3691
{
3692
+ if let hir:: Expr { kind : hir:: ExprKind :: MethodCall ( _, rcvr, _, _) , .. } = expr
3693
+ && let Some ( ty) = typeck_results. node_type_opt ( rcvr. hir_id )
3694
+ && let Some ( failed_pred) = failed_pred. to_opt_poly_trait_pred ( )
3695
+ && let pred = failed_pred. map_bound ( |pred| pred. with_self_ty ( tcx, ty) )
3696
+ && self . predicate_must_hold_modulo_regions ( & Obligation :: misc (
3697
+ tcx, expr. span , body_id, param_env, pred,
3698
+ ) )
3699
+ {
3700
+ err. span_suggestion_verbose (
3701
+ expr. span . with_lo ( rcvr. span . hi ( ) ) ,
3702
+ format ! (
3703
+ "consider removing this method call, as the receiver has type `{ty}` and \
3704
+ `{pred}` trivially holds",
3705
+ ) ,
3706
+ "" ,
3707
+ Applicability :: MaybeIncorrect ,
3708
+ ) ;
3709
+ }
3692
3710
if let hir:: Expr { kind : hir:: ExprKind :: Block ( block, _) , .. } = expr {
3693
3711
let inner_expr = expr. peel_blocks ( ) ;
3694
3712
let ty = typeck_results
@@ -3824,7 +3842,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
3824
3842
}
3825
3843
}
3826
3844
3827
- if let Node :: Expr ( expr) = tcx . hir_node ( call_hir_id ) {
3845
+ if let Node :: Expr ( expr) = call_node {
3828
3846
if let hir:: ExprKind :: Call ( hir:: Expr { span, .. } , _)
3829
3847
| hir:: ExprKind :: MethodCall (
3830
3848
hir:: PathSegment { ident : Ident { span, .. } , .. } ,
0 commit comments