about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCameron Steffen <cam.steffen94@gmail.com>2020-11-23 13:20:53 -0600
committerflip1995 <philipp.krones@embecosm.com>2021-01-02 18:25:40 +0100
commitf74e2001b94fa67ecef00bdb7de1e120f9cf0ec8 (patch)
treeeb0226e5c725ecd55e5be67ebcbe17be98cac9c2
parent173e1ba966d92570cbf64d65e2f7353bcab1c661 (diff)
downloadrust-f74e2001b94fa67ecef00bdb7de1e120f9cf0ec8.tar.gz
rust-f74e2001b94fa67ecef00bdb7de1e120f9cf0ec8.zip
Remove redundant shadow check
There is already an assertion that consecutive lines assign to a struct
field.
-rw-r--r--clippy_lints/src/default.rs20
1 files changed, 2 insertions, 18 deletions
diff --git a/clippy_lints/src/default.rs b/clippy_lints/src/default.rs
index adcc17266d2..c3fe77f6250 100644
--- a/clippy_lints/src/default.rs
+++ b/clippy_lints/src/default.rs
@@ -122,15 +122,8 @@ impl LateLintPass<'_> for Default {
             let mut assigned_fields = Vec::new();
             let mut cancel_lint = false;
             for consecutive_statement in &block.stmts[stmt_idx + 1..] {
-                // interrupt if the statement is a let binding (`Local`) that shadows the original
-                // binding
-                if stmt_shadows_binding(consecutive_statement, binding_name) {
-                    break;
-                }
                 // find out if and which field was set by this `consecutive_statement`
-                else if let Some((field_ident, assign_rhs)) =
-                    field_reassigned_by_stmt(consecutive_statement, binding_name)
-                {
+                if let Some((field_ident, assign_rhs)) = field_reassigned_by_stmt(consecutive_statement, binding_name) {
                     // interrupt and cancel lint if assign_rhs references the original binding
                     if contains_name(binding_name, assign_rhs) {
                         cancel_lint = true;
@@ -152,7 +145,7 @@ impl LateLintPass<'_> for Default {
                         first_assign = Some(consecutive_statement);
                     }
                 }
-                // interrupt also if no field was assigned, since we only want to look at consecutive statements
+                // interrupt if no field was assigned, since we only want to look at consecutive statements
                 else {
                     break;
                 }
@@ -256,15 +249,6 @@ fn enumerate_bindings_using_default<'tcx>(
         .collect()
 }
 
-fn stmt_shadows_binding(this: &Stmt<'_>, shadowed: Symbol) -> bool {
-    if let StmtKind::Local(local) = &this.kind {
-        if let PatKind::Binding(_, _, ident, _) = local.pat.kind {
-            return ident.name == shadowed;
-        }
-    }
-    false
-}
-
 /// Returns the reassigned field and the assigning expression (right-hand side of assign).
 fn field_reassigned_by_stmt<'tcx>(this: &Stmt<'tcx>, binding_name: Symbol) -> Option<(Ident, &'tcx Expr<'tcx>)> {
     if_chain! {