@@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
2
2
use clippy_utils:: ty:: is_type_diagnostic_item;
3
3
use clippy_utils:: { is_expr_untyped_identity_function, is_mutable, is_trait_method, path_to_local} ;
4
4
use rustc_errors:: Applicability ;
5
- use rustc_hir:: { self as hir, Node , PatKind } ;
5
+ use rustc_hir:: { self as hir, ExprKind , Node , PatKind } ;
6
6
use rustc_lint:: LateContext ;
7
7
use rustc_span:: { Span , Symbol , sym} ;
8
8
@@ -39,7 +39,13 @@ pub(super) fn check(
39
39
}
40
40
}
41
41
42
- let method_requiring_mut = String :: from ( "random_method" ) ; // TODO
42
+ let method_requiring_mut = if let Node :: Expr ( expr) = cx. tcx . parent_hir_node ( expr. hir_id )
43
+ && let ExprKind :: MethodCall ( method, ..) = expr. kind
44
+ {
45
+ Some ( method. ident )
46
+ } else {
47
+ None
48
+ } ;
43
49
44
50
span_lint_and_then (
45
51
cx,
@@ -57,10 +63,14 @@ pub(super) fn check(
57
63
} ,
58
64
) ;
59
65
if !apply {
60
- diag. span_note (
61
- caller. span ,
62
- format ! ( "this must be made mutable to use `{method_requiring_mut}`" ) ,
63
- ) ;
66
+ if let Some ( method_requiring_mut) = method_requiring_mut {
67
+ diag. span_note (
68
+ caller. span ,
69
+ format ! ( "this must be made mutable to use `{method_requiring_mut}`" ) ,
70
+ ) ;
71
+ } else {
72
+ diag. span_note ( caller. span , format ! ( "this must be made mutable" ) ) ;
73
+ }
64
74
}
65
75
} ,
66
76
) ;
0 commit comments