@@ -3,14 +3,12 @@ use clippy_utils::is_from_proc_macro;
3
3
use clippy_utils:: ty:: needs_ordered_drop;
4
4
use rustc_ast:: Mutability ;
5
5
use rustc_hir:: def:: Res ;
6
- use rustc_hir:: { BindingAnnotation , ByRef , Expr , ExprKind , HirId , Local , Node , Pat , PatKind , QPath } ;
7
- use rustc_infer:: infer:: TyCtxtInferExt ;
6
+ use rustc_hir:: { BindingAnnotation , ByRef , ExprKind , HirId , Local , Node , Pat , PatKind , QPath } ;
8
7
use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
9
8
use rustc_middle:: lint:: in_external_macro;
10
9
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
11
10
use rustc_span:: symbol:: Ident ;
12
11
use rustc_span:: DesugaringKind ;
13
- use rustc_trait_selection:: infer:: InferCtxtExt as _;
14
12
15
13
declare_clippy_lint ! {
16
14
/// ### What it does
@@ -68,18 +66,10 @@ impl<'tcx> LateLintPass<'tcx> for RedundantLocals {
68
66
// the local does not change the effect of assignments to the binding. see #11290
69
67
if !affects_assignments( cx, mutability, binding_id, local. hir_id) ;
70
68
// the local does not affect the code's drop behavior
71
- if !affects_drop_behavior ( cx, binding_id , local . hir_id , expr) ;
69
+ if !needs_ordered_drop ( cx, cx . typeck_results ( ) . expr_ty ( expr) ) ;
72
70
// the local is user-controlled
73
71
if !in_external_macro( cx. sess( ) , local. span) ;
74
72
if !is_from_proc_macro( cx, expr) ;
75
- // the local does not impl Drop trait. see #11599
76
- let local_ty = cx. typeck_results( ) . node_type( local. hir_id) ;
77
- if let Some ( drop_trait_id) = cx. tcx. lang_items( ) . drop_trait( ) ;
78
- if !cx. tcx. infer_ctxt( ) . build( ) . type_implements_trait(
79
- drop_trait_id,
80
- [ local_ty] ,
81
- cx. param_env
82
- ) . must_apply_modulo_regions( ) ;
83
73
then {
84
74
span_lint_and_help(
85
75
cx,
@@ -114,13 +104,3 @@ fn affects_assignments(cx: &LateContext<'_>, mutability: Mutability, bind: HirId
114
104
// the binding is mutable and the rebinding is in a different scope than the original binding
115
105
mutability == Mutability :: Mut && hir. get_enclosing_scope ( bind) != hir. get_enclosing_scope ( rebind)
116
106
}
117
-
118
- /// Check if a rebinding of a local affects the code's drop behavior.
119
- fn affects_drop_behavior < ' tcx > ( cx : & LateContext < ' tcx > , bind : HirId , rebind : HirId , rebind_expr : & Expr < ' tcx > ) -> bool {
120
- let hir = cx. tcx . hir ( ) ;
121
-
122
- // the rebinding is in a different scope than the original binding
123
- // and the type of the binding cares about drop order
124
- hir. get_enclosing_scope ( bind) != hir. get_enclosing_scope ( rebind)
125
- && needs_ordered_drop ( cx, cx. typeck_results ( ) . expr_ty ( rebind_expr) )
126
- }
0 commit comments