@@ -4,24 +4,28 @@ use clippy_utils::sym;
44use rustc_errors:: Applicability ;
55use rustc_hir:: Expr ;
66use rustc_lint:: LateContext ;
7- use rustc_span:: Span ;
7+ use rustc_span:: { Span , Symbol } ;
88
9- use super :: { OPTION_AS_REF_CLONED , method_call } ;
9+ use super :: OPTION_AS_REF_CLONED ;
1010
11- pub ( super ) fn check ( cx : & LateContext < ' _ > , cloned_recv : & Expr < ' _ > , cloned_ident_span : Span ) {
12- if let Some ( ( method @ ( sym:: as_ref | sym:: as_mut) , as_ref_recv, [ ] , as_ref_ident_span, _) ) =
13- method_call ( cloned_recv)
14- && cx
15- . typeck_results ( )
16- . expr_ty ( as_ref_recv)
17- . peel_refs ( )
18- . is_diag_item ( cx, sym:: Option )
11+ pub ( super ) fn check (
12+ cx : & LateContext < ' _ > ,
13+ cloned_ident_span : Span ,
14+ as_ref_method : Symbol ,
15+ as_ref_recv : & Expr < ' _ > ,
16+ as_ref_ident_span : Span ,
17+ ) {
18+ if cx
19+ . typeck_results ( )
20+ . expr_ty ( as_ref_recv)
21+ . peel_refs ( )
22+ . is_diag_item ( cx, sym:: Option )
1923 {
2024 span_lint_and_sugg (
2125 cx,
2226 OPTION_AS_REF_CLONED ,
2327 as_ref_ident_span. to ( cloned_ident_span) ,
24- format ! ( "cloning an `Option<_>` using `.{method }().cloned()`" ) ,
28+ format ! ( "cloning an `Option<_>` using `.{as_ref_method }().cloned()`" ) ,
2529 "this can be written more concisely by cloning the `Option<_>` directly" ,
2630 "clone" . into ( ) ,
2731 Applicability :: MachineApplicable ,
0 commit comments