Skip to content

Commit d9a88be

Browse files
committed
Rename get_offset and its private items
1 parent 8da6cfd commit d9a88be

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

clippy_lints/src/loops.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -942,20 +942,20 @@ fn fetch_cloned_expr<'tcx>(expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> {
942942
}
943943
}
944944

945-
fn get_offset<'tcx>(
945+
fn get_details_from_idx<'tcx>(
946946
cx: &LateContext<'tcx>,
947947
idx: &Expr<'_>,
948948
starts: &[Start<'tcx>],
949949
) -> Option<(StartKind<'tcx>, Offset)> {
950-
fn extract_start<'tcx>(
950+
fn get_start<'tcx>(
951951
cx: &LateContext<'tcx>,
952-
expr: &Expr<'_>,
952+
e: &Expr<'_>,
953953
starts: &[Start<'tcx>],
954954
) -> Option<StartKind<'tcx>> {
955-
starts.iter().find(|var| same_var(cx, expr, var.id)).map(|v| v.kind)
955+
starts.iter().find(|var| same_var(cx, e, var.id)).map(|v| v.kind)
956956
}
957957

958-
fn extract_offset<'tcx>(
958+
fn get_offset<'tcx>(
959959
cx: &LateContext<'tcx>,
960960
e: &Expr<'_>,
961961
starts: &[Start<'tcx>],
@@ -965,7 +965,7 @@ fn get_offset<'tcx>(
965965
ast::LitKind::Int(x, _ty) => Some(MinifyingSugg::non_paren(x.to_string())),
966966
_ => None,
967967
},
968-
ExprKind::Path(..) if extract_start(cx, e, starts).is_none() => {
968+
ExprKind::Path(..) if get_start(cx, e, starts).is_none() => {
969969
// `e` is always non paren as it's a `Path`
970970
Some(MinifyingSugg::non_paren(snippet(cx, e.span, "???")))
971971
},
@@ -976,21 +976,22 @@ fn get_offset<'tcx>(
976976
match idx.kind {
977977
ExprKind::Binary(op, lhs, rhs) => match op.node {
978978
BinOpKind::Add => {
979-
let offset_opt = if let Some(s) = extract_start(cx, lhs, starts) {
980-
extract_offset(cx, rhs, starts).map(|o| (s, o))
981-
} else if let Some(s) = extract_start(cx, rhs, starts) {
982-
extract_offset(cx, lhs, starts).map(|o| (s, o))
979+
let offset_opt = if let Some(s) = get_start(cx, lhs, starts) {
980+
get_offset(cx, rhs, starts).map(|o| (s, o))
981+
} else if let Some(s) = get_start(cx, rhs, starts) {
982+
get_offset(cx, lhs, starts).map(|o| (s, o))
983983
} else {
984984
None
985985
};
986986

987987
offset_opt.map(|(s, o)| (s, Offset::positive(o)))
988988
},
989-
BinOpKind::Sub => extract_start(cx, lhs, starts)
990-
.and_then(|s| extract_offset(cx, rhs, starts).map(|o| (s, Offset::negative(o)))),
989+
BinOpKind::Sub => {
990+
get_start(cx, lhs, starts).and_then(|s| get_offset(cx, rhs, starts).map(|o| (s, Offset::negative(o))))
991+
},
991992
_ => None,
992993
},
993-
ExprKind::Path(..) => extract_start(cx, idx, starts).map(|s| (s, Offset::empty())),
994+
ExprKind::Path(..) => get_start(cx, idx, starts).map(|s| (s, Offset::empty())),
994995
_ => None,
995996
}
996997
}
@@ -1196,8 +1197,8 @@ fn detect_manual_memcpy<'tcx>(
11961197
if let ExprKind::Index(base_right, idx_right) = rhs.kind;
11971198
if is_slice_like(cx, cx.typeck_results().expr_ty(base_left))
11981199
&& is_slice_like(cx, cx.typeck_results().expr_ty(base_right));
1199-
if let Some((start_left, offset_left)) = get_offset(cx, &idx_left, &starts);
1200-
if let Some((start_right, offset_right)) = get_offset(cx, &idx_right, &starts);
1200+
if let Some((start_left, offset_left)) = get_details_from_idx(cx, &idx_left, &starts);
1201+
if let Some((start_right, offset_right)) = get_details_from_idx(cx, &idx_right, &starts);
12011202

12021203
// Source and destination must be different
12031204
if var_def_id(cx, base_left) != var_def_id(cx, base_right);

0 commit comments

Comments
 (0)