@@ -3,14 +3,12 @@ use clippy_utils::is_from_proc_macro;
33use clippy_utils:: ty:: needs_ordered_drop;
44use rustc_ast:: Mutability ;
55use 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 } ;
87use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
98use rustc_middle:: lint:: in_external_macro;
109use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
1110use rustc_span:: symbol:: Ident ;
1211use rustc_span:: DesugaringKind ;
13- use rustc_trait_selection:: infer:: InferCtxtExt as _;
1412
1513declare_clippy_lint ! {
1614 /// ### What it does
@@ -68,18 +66,10 @@ impl<'tcx> LateLintPass<'tcx> for RedundantLocals {
6866 // the local does not change the effect of assignments to the binding. see #11290
6967 if !affects_assignments( cx, mutability, binding_id, local. hir_id) ;
7068 // 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) ) ;
7270 // the local is user-controlled
7371 if !in_external_macro( cx. sess( ) , local. span) ;
7472 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( ) ;
8373 then {
8474 span_lint_and_help(
8575 cx,
@@ -114,13 +104,3 @@ fn affects_assignments(cx: &LateContext<'_>, mutability: Mutability, bind: HirId
114104 // the binding is mutable and the rebinding is in a different scope than the original binding
115105 mutability == Mutability :: Mut && hir. get_enclosing_scope ( bind) != hir. get_enclosing_scope ( rebind)
116106}
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