Skip to content

Commit 7e18f4f

Browse files
committed
Move type equality check to just before push
1 parent 4a53f00 commit 7e18f4f

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

clippy_lints/src/dereference.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,20 +1127,17 @@ fn replace_types<'tcx>(
11271127
deque.push_back((param_ty, new_ty));
11281128

11291129
while let Some((param_ty, new_ty)) = deque.pop_front() {
1130-
let new_generic_arg = ty::GenericArg::from(new_ty);
1131-
11321130
// If `replaced.is_empty()`, then `param_ty` and `new_ty` are those initially passed in.
1133-
if substs[param_ty.index as usize] != new_generic_arg
1134-
&& !fn_sig
1135-
.inputs_and_output
1136-
.iter()
1137-
.enumerate()
1138-
.all(|(i, ty)| (replaced.is_empty() && i == arg_index) || !contains_ty(ty, param_ty.to_ty(cx.tcx)))
1131+
if !fn_sig
1132+
.inputs_and_output
1133+
.iter()
1134+
.enumerate()
1135+
.all(|(i, ty)| (replaced.is_empty() && i == arg_index) || !contains_ty(ty, param_ty.to_ty(cx.tcx)))
11391136
{
11401137
return false;
11411138
}
11421139

1143-
substs[param_ty.index as usize] = new_generic_arg;
1140+
substs[param_ty.index as usize] = ty::GenericArg::from(new_ty);
11441141

11451142
// The `replaced.insert(...)` check provides some protection against infinite loops.
11461143
if replaced.insert(param_ty.index) {
@@ -1155,7 +1152,9 @@ fn replace_types<'tcx>(
11551152
.mk_projection(assoc_item.def_id, cx.tcx.mk_substs_trait(new_ty, &[]));
11561153
let projected_ty = cx.tcx.normalize_erasing_regions(cx.param_env, projection);
11571154

1158-
deque.push_back((*term_param_ty, projected_ty));
1155+
if substs[term_param_ty.index as usize] != ty::GenericArg::from(projected_ty) {
1156+
deque.push_back((*term_param_ty, projected_ty));
1157+
}
11591158
}
11601159
}
11611160
}

0 commit comments

Comments
 (0)