1
1
use clippy_utils:: diagnostics:: { span_lint_and_sugg, span_lint_and_then} ;
2
2
use clippy_utils:: higher:: VecArgs ;
3
3
use clippy_utils:: source:: snippet_opt;
4
+ use clippy_utils:: ty:: is_type_diagnostic_item;
4
5
use clippy_utils:: usage:: local_used_after_expr;
5
6
use clippy_utils:: { get_enclosing_loop_or_closure, higher, path_to_local, path_to_local_id} ;
6
7
use if_chain:: if_chain;
@@ -12,6 +13,7 @@ use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
12
13
use rustc_middle:: ty:: subst:: Subst ;
13
14
use rustc_middle:: ty:: { self , ClosureKind , Ty , TypeFoldable } ;
14
15
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
16
+ use rustc_span:: symbol:: sym;
15
17
16
18
declare_clippy_lint ! {
17
19
/// ### What it does
@@ -113,6 +115,9 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
113
115
// A type param function ref like `T::f` is not 'static, however
114
116
// it is if cast like `T::f as fn()`. This seems like a rustc bug.
115
117
if !substs. types( ) . any( |t| matches!( t. kind( ) , ty:: Param ( _) ) ) ;
118
+ let callee_ty_unadjusted = cx. typeck_results( ) . expr_ty( callee) . peel_refs( ) ;
119
+ if !is_type_diagnostic_item( cx, callee_ty_unadjusted, sym:: Arc ) ;
120
+ if !is_type_diagnostic_item( cx, callee_ty_unadjusted, sym:: Rc ) ;
116
121
then {
117
122
span_lint_and_then( cx, REDUNDANT_CLOSURE , expr. span, "redundant closure" , |diag| {
118
123
if let Some ( mut snippet) = snippet_opt( cx, callee. span) {
0 commit comments