Skip to content

Commit c8c03ea

Browse files
committed
Auto merge of #10793 - c410-f3r:bbbbbbbbbbb, r=xFrednet
[`arithmetic_side_effects`] Fix #10792 Fix #10792 ``` changelog: [`arithmetic_side_effects`]: Retrieve field values of structures that are in constant environments ```
2 parents ebcbba9 + dbe4057 commit c8c03ea

File tree

9 files changed

+114
-72
lines changed

9 files changed

+114
-72
lines changed

clippy_lints/src/enum_clike.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant {
5151
.const_eval_poly(def_id.to_def_id())
5252
.ok()
5353
.map(|val| rustc_middle::mir::ConstantKind::from_value(val, ty));
54-
if let Some(Constant::Int(val)) = constant.and_then(|c| miri_to_const(cx.tcx, c)) {
54+
if let Some(Constant::Int(val)) = constant.and_then(|c| miri_to_const(cx, c)) {
5555
if let ty::Adt(adt, _) = ty.kind() {
5656
if adt.is_enum() {
5757
ty = adt.repr().discr_type().to_ty(cx.tcx);

clippy_lints/src/floating_point_arithmetic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ fn check_ln1p(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>) {
215215
// ranges [-16777215, 16777216) for type f32 as whole number floats outside
216216
// this range are lossy and ambiguous.
217217
#[expect(clippy::cast_possible_truncation)]
218-
fn get_integer_from_float_constant(value: &Constant) -> Option<i32> {
218+
fn get_integer_from_float_constant(value: &Constant<'_>) -> Option<i32> {
219219
match value {
220220
F32(num) if num.fract() == 0.0 => {
221221
if (-16_777_215.0..16_777_216.0).contains(num) {

clippy_lints/src/matches/overlapping_arms.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
4141
cx.tcx.valtree_to_const_val((ty, min_val_const.to_valtree())),
4242
ty,
4343
);
44-
miri_to_const(cx.tcx, min_constant)?
44+
miri_to_const(cx, min_constant)?
4545
},
4646
};
4747
let rhs_const = match rhs {
@@ -52,7 +52,7 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
5252
cx.tcx.valtree_to_const_val((ty, max_val_const.to_valtree())),
5353
ty,
5454
);
55-
miri_to_const(cx.tcx, max_constant)?
55+
miri_to_const(cx, max_constant)?
5656
},
5757
};
5858
let lhs_val = lhs_const.int_value(cx, ty)?;

clippy_lints/src/minmax.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ enum MinMax {
6666
Max,
6767
}
6868

69-
fn min_max<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(MinMax, Constant, &'a Expr<'a>)> {
69+
fn min_max<'a, 'tcx>(cx: &LateContext<'tcx>, expr: &'a Expr<'a>) -> Option<(MinMax, Constant<'tcx>, &'a Expr<'a>)> {
7070
match expr.kind {
7171
ExprKind::Call(path, args) => {
7272
if let ExprKind::Path(ref qpath) = path.kind {
@@ -99,12 +99,12 @@ fn min_max<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(MinMax, Cons
9999
}
100100
}
101101

102-
fn fetch_const<'a>(
103-
cx: &LateContext<'_>,
102+
fn fetch_const<'a, 'tcx>(
103+
cx: &LateContext<'tcx>,
104104
receiver: Option<&'a Expr<'a>>,
105105
args: &'a [Expr<'a>],
106106
m: MinMax,
107-
) -> Option<(MinMax, Constant, &'a Expr<'a>)> {
107+
) -> Option<(MinMax, Constant<'tcx>, &'a Expr<'a>)> {
108108
let mut args = receiver.into_iter().chain(args);
109109
let first_arg = args.next()?;
110110
let second_arg = args.next()?;

clippy_lints/src/operators/float_cmp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn get_lint_and_message(is_local: bool, is_comparing_arrays: bool) -> (&'static
8585
}
8686
}
8787

88-
fn is_allowed(val: &Constant) -> bool {
88+
fn is_allowed(val: &Constant<'_>) -> bool {
8989
match val {
9090
&Constant::F32(f) => f == 0.0 || f.is_infinite(),
9191
&Constant::F64(f) => f == 0.0 || f.is_infinite(),

clippy_lints/src/ranges.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ fn check_possible_range_contains(
296296
}
297297
}
298298

299-
struct RangeBounds<'a> {
300-
val: Constant,
299+
struct RangeBounds<'a, 'tcx> {
300+
val: Constant<'tcx>,
301301
expr: &'a Expr<'a>,
302302
id: HirId,
303303
name_span: Span,
@@ -309,7 +309,7 @@ struct RangeBounds<'a> {
309309
// Takes a binary expression such as x <= 2 as input
310310
// Breaks apart into various pieces, such as the value of the number,
311311
// hir id of the variable, and direction/inclusiveness of the operator
312-
fn check_range_bounds<'a>(cx: &'a LateContext<'_>, ex: &'a Expr<'_>) -> Option<RangeBounds<'a>> {
312+
fn check_range_bounds<'a, 'tcx>(cx: &'a LateContext<'tcx>, ex: &'a Expr<'_>) -> Option<RangeBounds<'a, 'tcx>> {
313313
if let ExprKind::Binary(ref op, l, r) = ex.kind {
314314
let (inclusive, ordering) = match op.node {
315315
BinOpKind::Gt => (false, Ordering::Greater),

0 commit comments

Comments
 (0)