Skip to content

Commit f74e200

Browse files
camsteffenflip1995
authored andcommitted
Remove redundant shadow check
There is already an assertion that consecutive lines assign to a struct field.
1 parent 173e1ba commit f74e200

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

clippy_lints/src/default.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,8 @@ impl LateLintPass<'_> for Default {
122122
let mut assigned_fields = Vec::new();
123123
let mut cancel_lint = false;
124124
for consecutive_statement in &block.stmts[stmt_idx + 1..] {
125-
// interrupt if the statement is a let binding (`Local`) that shadows the original
126-
// binding
127-
if stmt_shadows_binding(consecutive_statement, binding_name) {
128-
break;
129-
}
130125
// find out if and which field was set by this `consecutive_statement`
131-
else if let Some((field_ident, assign_rhs)) =
132-
field_reassigned_by_stmt(consecutive_statement, binding_name)
133-
{
126+
if let Some((field_ident, assign_rhs)) = field_reassigned_by_stmt(consecutive_statement, binding_name) {
134127
// interrupt and cancel lint if assign_rhs references the original binding
135128
if contains_name(binding_name, assign_rhs) {
136129
cancel_lint = true;
@@ -152,7 +145,7 @@ impl LateLintPass<'_> for Default {
152145
first_assign = Some(consecutive_statement);
153146
}
154147
}
155-
// interrupt also if no field was assigned, since we only want to look at consecutive statements
148+
// interrupt if no field was assigned, since we only want to look at consecutive statements
156149
else {
157150
break;
158151
}
@@ -256,15 +249,6 @@ fn enumerate_bindings_using_default<'tcx>(
256249
.collect()
257250
}
258251

259-
fn stmt_shadows_binding(this: &Stmt<'_>, shadowed: Symbol) -> bool {
260-
if let StmtKind::Local(local) = &this.kind {
261-
if let PatKind::Binding(_, _, ident, _) = local.pat.kind {
262-
return ident.name == shadowed;
263-
}
264-
}
265-
false
266-
}
267-
268252
/// Returns the reassigned field and the assigning expression (right-hand side of assign).
269253
fn field_reassigned_by_stmt<'tcx>(this: &Stmt<'tcx>, binding_name: Symbol) -> Option<(Ident, &'tcx Expr<'tcx>)> {
270254
if_chain! {

0 commit comments

Comments
 (0)