Skip to content

Commit f6b70da

Browse files
committed
Require ConstEvalCtxt to be constructed.
1 parent 8343046 commit f6b70da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+269
-277
lines changed

clippy_lints/src/assertions_on_constants.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::consts::{constant, Constant};
1+
use clippy_utils::consts::{ConstEvalCtxt, Constant};
22
use clippy_utils::diagnostics::span_lint_and_help;
33
use clippy_utils::is_inside_always_const_context;
44
use clippy_utils::macros::{find_assert_args, root_macro_call_first_node, PanicExpn};
@@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants {
4343
let Some((condition, panic_expn)) = find_assert_args(cx, e, macro_call.expn) else {
4444
return;
4545
};
46-
let Some(Constant::Bool(val)) = constant(cx, cx.typeck_results(), condition) else {
46+
let Some(Constant::Bool(val)) = ConstEvalCtxt::new(cx).eval(condition) else {
4747
return;
4848
};
4949

clippy_lints/src/casts/cast_nan_to_int.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::CAST_NAN_TO_INT;
22

3-
use clippy_utils::consts::{constant, Constant};
3+
use clippy_utils::consts::{ConstEvalCtxt, Constant};
44
use clippy_utils::diagnostics::span_lint_and_note;
55
use rustc_hir::Expr;
66
use rustc_lint::LateContext;
@@ -20,7 +20,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
2020
}
2121

2222
fn is_known_nan(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
23-
match constant(cx, cx.typeck_results(), e) {
23+
match ConstEvalCtxt::new(cx).eval(e) {
2424
// FIXME(f16_f128): add these types when nan checks are available on all platforms
2525
Some(Constant::F64(n)) => n.is_nan(),
2626
Some(Constant::F32(n)) => n.is_nan(),

clippy_lints/src/casts/cast_possible_truncation.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::consts::{constant, Constant};
1+
use clippy_utils::consts::{ConstEvalCtxt, Constant};
22
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
33
use clippy_utils::expr_or_init;
44
use clippy_utils::source::snippet;
@@ -15,7 +15,7 @@ use rustc_target::abi::IntegerType;
1515
use super::{utils, CAST_ENUM_TRUNCATION, CAST_POSSIBLE_TRUNCATION};
1616

1717
fn constant_int(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<u128> {
18-
if let Some(Constant::Int(c)) = constant(cx, cx.typeck_results(), expr) {
18+
if let Some(Constant::Int(c)) = ConstEvalCtxt::new(cx).eval(expr) {
1919
Some(c)
2020
} else {
2121
None

clippy_lints/src/casts/cast_sign_loss.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::convert::Infallible;
22
use std::ops::ControlFlow;
33

4-
use clippy_utils::consts::{constant, Constant};
4+
use clippy_utils::consts::{ConstEvalCtxt, Constant};
55
use clippy_utils::diagnostics::span_lint;
66
use clippy_utils::visitors::{for_each_expr_without_closures, Descend};
77
use clippy_utils::{method_chain_args, sext};
@@ -88,7 +88,7 @@ fn get_const_signed_int_eval<'cx>(
8888
) -> Option<i128> {
8989
let ty = ty.into().unwrap_or_else(|| cx.typeck_results().expr_ty(expr));
9090

91-
if let Constant::Int(n) = constant(cx, cx.typeck_results(), expr)?
91+
if let Constant::Int(n) = ConstEvalCtxt::new(cx).eval(expr)?
9292
&& let ty::Int(ity) = *ty.kind()
9393
{
9494
return Some(sext(cx.tcx, n, ity));
@@ -103,7 +103,7 @@ fn get_const_unsigned_int_eval<'cx>(
103103
) -> Option<u128> {
104104
let ty = ty.into().unwrap_or_else(|| cx.typeck_results().expr_ty(expr));
105105

106-
if let Constant::Int(n) = constant(cx, cx.typeck_results(), expr)?
106+
if let Constant::Int(n) = ConstEvalCtxt::new(cx).eval(expr)?
107107
&& let ty::Uint(_ity) = *ty.kind()
108108
{
109109
return Some(n);

clippy_lints/src/floating_point_arithmetic.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::consts::Constant::{Int, F32, F64};
2-
use clippy_utils::consts::{constant, constant_simple, Constant};
2+
use clippy_utils::consts::{ConstEvalCtxt, Constant};
33
use clippy_utils::diagnostics::span_lint_and_sugg;
44
use clippy_utils::{
55
eq_expr_value, get_parent_expr, higher, in_constant, is_inherent_method_call, is_no_std_crate, numeric_literal,
@@ -112,7 +112,7 @@ declare_lint_pass!(FloatingPointArithmetic => [
112112
// Returns the specialized log method for a given base if base is constant
113113
// and is one of 2, 10 and e
114114
fn get_specialized_log_method(cx: &LateContext<'_>, base: &Expr<'_>) -> Option<&'static str> {
115-
if let Some(value) = constant(cx, cx.typeck_results(), base) {
115+
if let Some(value) = ConstEvalCtxt::new(cx).eval(base) {
116116
if F32(2.0) == value || F64(2.0) == value {
117117
return Some("log2");
118118
} else if F32(10.0) == value || F64(10.0) == value {
@@ -182,10 +182,8 @@ fn check_ln1p(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>) {
182182
rhs,
183183
) = receiver.kind
184184
{
185-
let recv = match (
186-
constant(cx, cx.typeck_results(), lhs),
187-
constant(cx, cx.typeck_results(), rhs),
188-
) {
185+
let ecx = ConstEvalCtxt::new(cx);
186+
let recv = match (ecx.eval(lhs), ecx.eval(rhs)) {
189187
(Some(value), _) if F32(1.0) == value || F64(1.0) == value => rhs,
190188
(_, Some(value)) if F32(1.0) == value || F64(1.0) == value => lhs,
191189
_ => return,
@@ -230,7 +228,7 @@ fn get_integer_from_float_constant(value: &Constant<'_>) -> Option<i32> {
230228

231229
fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>, args: &[Expr<'_>]) {
232230
// Check receiver
233-
if let Some(value) = constant(cx, cx.typeck_results(), receiver) {
231+
if let Some(value) = ConstEvalCtxt::new(cx).eval(receiver) {
234232
if let Some(method) = if F32(f32_consts::E) == value || F64(f64_consts::E) == value {
235233
Some("exp")
236234
} else if F32(2.0) == value || F64(2.0) == value {
@@ -251,7 +249,7 @@ fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>, args:
251249
}
252250

253251
// Check argument
254-
if let Some(value) = constant(cx, cx.typeck_results(), &args[0]) {
252+
if let Some(value) = ConstEvalCtxt::new(cx).eval(&args[0]) {
255253
let (lint, help, suggestion) = if F32(1.0 / 2.0) == value || F64(1.0 / 2.0) == value {
256254
(
257255
SUBOPTIMAL_FLOPS,
@@ -291,7 +289,7 @@ fn check_powf(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>, args:
291289
}
292290

293291
fn check_powi(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>, args: &[Expr<'_>]) {
294-
if let Some(value) = constant(cx, cx.typeck_results(), &args[0]) {
292+
if let Some(value) = ConstEvalCtxt::new(cx).eval(&args[0]) {
295293
if value == Int(2) {
296294
if let Some(parent) = get_parent_expr(cx, expr) {
297295
if let Some(grandparent) = get_parent_expr(cx, parent) {
@@ -397,8 +395,9 @@ fn detect_hypot(cx: &LateContext<'_>, receiver: &Expr<'_>) -> Option<String> {
397395
) = &add_rhs.kind
398396
&& lmethod_name.as_str() == "powi"
399397
&& rmethod_name.as_str() == "powi"
400-
&& let Some(lvalue) = constant(cx, cx.typeck_results(), largs_1)
401-
&& let Some(rvalue) = constant(cx, cx.typeck_results(), rargs_1)
398+
&& let ecx = ConstEvalCtxt::new(cx)
399+
&& let Some(lvalue) = ecx.eval(largs_1)
400+
&& let Some(rvalue) = ecx.eval(rargs_1)
402401
&& Int(2) == lvalue
403402
&& Int(2) == rvalue
404403
{
@@ -438,7 +437,7 @@ fn check_expm1(cx: &LateContext<'_>, expr: &Expr<'_>) {
438437
rhs,
439438
) = expr.kind
440439
&& cx.typeck_results().expr_ty(lhs).is_floating_point()
441-
&& let Some(value) = constant(cx, cx.typeck_results(), rhs)
440+
&& let Some(value) = ConstEvalCtxt::new(cx).eval(rhs)
442441
&& (F32(1.0) == value || F64(1.0) == value)
443442
&& let ExprKind::MethodCall(path, self_arg, ..) = &lhs.kind
444443
&& cx.typeck_results().expr_ty(self_arg).is_floating_point()
@@ -552,7 +551,7 @@ fn is_testing_negative(cx: &LateContext<'_>, expr: &Expr<'_>, test: &Expr<'_>) -
552551

553552
/// Returns true iff expr is some zero literal
554553
fn is_zero(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
555-
match constant_simple(cx, cx.typeck_results(), expr) {
554+
match ConstEvalCtxt::new(cx).eval_simple(expr) {
556555
Some(Int(i)) => i == 0,
557556
Some(F32(f)) => f == 0.0,
558557
Some(F64(f)) => f == 0.0,
@@ -696,8 +695,9 @@ fn check_radians(cx: &LateContext<'_>, expr: &Expr<'_>) {
696695
mul_lhs,
697696
mul_rhs,
698697
) = &div_lhs.kind
699-
&& let Some(rvalue) = constant(cx, cx.typeck_results(), div_rhs)
700-
&& let Some(lvalue) = constant(cx, cx.typeck_results(), mul_rhs)
698+
&& let ecx = ConstEvalCtxt::new(cx)
699+
&& let Some(rvalue) = ecx.eval(div_rhs)
700+
&& let Some(lvalue) = ecx.eval(mul_rhs)
701701
{
702702
// TODO: also check for constant values near PI/180 or 180/PI
703703
if (F32(f32_consts::PI) == rvalue || F64(f64_consts::PI) == rvalue)

clippy_lints/src/if_not_else.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! lint on if branches that could be swapped so no `!` operation is necessary
22
//! on the condition
33
4-
use clippy_utils::consts::{constant_simple, Constant};
4+
use clippy_utils::consts::{ConstEvalCtxt, Constant};
55
use clippy_utils::diagnostics::span_lint_and_help;
66
use clippy_utils::is_else_clause;
77
use rustc_hir::{BinOpKind, Expr, ExprKind, UnOp};
@@ -49,7 +49,7 @@ declare_clippy_lint! {
4949
declare_lint_pass!(IfNotElse => [IF_NOT_ELSE]);
5050

5151
fn is_zero_const(expr: &Expr<'_>, cx: &LateContext<'_>) -> bool {
52-
if let Some(value) = constant_simple(cx, cx.typeck_results(), expr) {
52+
if let Some(value) = ConstEvalCtxt::new(cx).eval_simple(expr) {
5353
return Constant::Int(0) == value;
5454
}
5555
false

clippy_lints/src/implicit_saturating_add.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::consts::{constant, Constant};
1+
use clippy_utils::consts::{ConstEvalCtxt, Constant};
22
use clippy_utils::diagnostics::span_lint_and_sugg;
33
use clippy_utils::get_parent_expr;
44
use clippy_utils::source::snippet_with_context;
@@ -117,11 +117,11 @@ fn get_int_max(ty: Ty<'_>) -> Option<u128> {
117117

118118
fn get_const<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -> Option<(u128, BinOpKind, &'tcx Expr<'tcx>)> {
119119
if let ExprKind::Binary(op, l, r) = expr.kind {
120-
let tr = cx.typeck_results();
121-
if let Some(Constant::Int(c)) = constant(cx, tr, r) {
120+
let ecx = ConstEvalCtxt::new(cx);
121+
if let Some(Constant::Int(c)) = ecx.eval(r) {
122122
return Some((c, op.node, l));
123123
};
124-
if let Some(Constant::Int(c)) = constant(cx, tr, l) {
124+
if let Some(Constant::Int(c)) = ecx.eval(l) {
125125
return Some((c, invert_op(op.node)?, r));
126126
}
127127
}

clippy_lints/src/index_refutable_slice.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_config::msrvs::{self, Msrv};
22
use clippy_config::Conf;
3-
use clippy_utils::consts::{constant, Constant};
3+
use clippy_utils::consts::{ConstEvalCtxt, Constant};
44
use clippy_utils::diagnostics::span_lint_and_then;
55
use clippy_utils::higher::IfLet;
66
use clippy_utils::ty::is_copy;
@@ -246,7 +246,7 @@ impl<'a, 'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'a, 'tcx> {
246246
&& let parent_id = cx.tcx.parent_hir_id(expr.hir_id)
247247
&& let hir::Node::Expr(parent_expr) = cx.tcx.hir_node(parent_id)
248248
&& let hir::ExprKind::Index(_, index_expr, _) = parent_expr.kind
249-
&& let Some(Constant::Int(index_value)) = constant(cx, cx.typeck_results(), index_expr)
249+
&& let Some(Constant::Int(index_value)) = ConstEvalCtxt::new(cx).eval(index_expr)
250250
&& let Ok(index_value) = index_value.try_into()
251251
&& index_value < max_suggested_slice
252252

clippy_lints/src/indexing_slicing.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! lint on indexing and slicing operations
22
33
use clippy_config::Conf;
4-
use clippy_utils::consts::{constant, Constant};
4+
use clippy_utils::consts::{ConstEvalCtxt, Constant};
55
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
66
use clippy_utils::ty::{deref_chain, get_adt_inherent_method};
77
use clippy_utils::{higher, is_from_proc_macro};
@@ -177,7 +177,7 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
177177
return;
178178
}
179179
// Index is a constant uint.
180-
if let Some(constant) = constant(cx, cx.typeck_results(), index) {
180+
if let Some(constant) = ConstEvalCtxt::new(cx).eval(index) {
181181
// only `usize` index is legal in rust array index
182182
// leave other type to rustc
183183
if let Constant::Int(off) = constant
@@ -215,14 +215,15 @@ impl<'tcx> LateLintPass<'tcx> for IndexingSlicing {
215215
/// Returns a tuple of options with the start and end (exclusive) values of
216216
/// the range. If the start or end is not constant, None is returned.
217217
fn to_const_range(cx: &LateContext<'_>, range: higher::Range<'_>, array_size: u128) -> (Option<u128>, Option<u128>) {
218-
let s = range.start.map(|expr| constant(cx, cx.typeck_results(), expr));
218+
let ecx = ConstEvalCtxt::new(cx);
219+
let s = range.start.map(|expr| ecx.eval(expr));
219220
let start = match s {
220221
Some(Some(Constant::Int(x))) => Some(x),
221222
Some(_) => None,
222223
None => Some(0),
223224
};
224225

225-
let e = range.end.map(|expr| constant(cx, cx.typeck_results(), expr));
226+
let e = range.end.map(|expr| ecx.eval(expr));
226227
let end = match e {
227228
Some(Some(Constant::Int(x))) => {
228229
if range.limits == RangeLimits::Closed {

clippy_lints/src/invalid_upcast_comparisons.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_span::Span;
77

88
use clippy_utils::comparisons;
99
use clippy_utils::comparisons::Rel;
10-
use clippy_utils::consts::{constant_full_int, FullInt};
10+
use clippy_utils::consts::{ConstEvalCtxt, FullInt};
1111
use clippy_utils::diagnostics::span_lint;
1212
use clippy_utils::source::snippet;
1313

@@ -95,7 +95,7 @@ fn upcast_comparison_bounds_err<'tcx>(
9595
invert: bool,
9696
) {
9797
if let Some((lb, ub)) = lhs_bounds {
98-
if let Some(norm_rhs_val) = constant_full_int(cx, cx.typeck_results(), rhs) {
98+
if let Some(norm_rhs_val) = ConstEvalCtxt::new(cx).eval_full_int(rhs) {
9999
if rel == Rel::Eq || rel == Rel::Ne {
100100
if norm_rhs_val < lb || norm_rhs_val > ub {
101101
err_upcast_comparison(cx, span, lhs, rel == Rel::Ne);

clippy_lints/src/loops/while_immutable_condition.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::WHILE_IMMUTABLE_CONDITION;
2-
use clippy_utils::consts::constant;
2+
use clippy_utils::consts::ConstEvalCtxt;
33
use clippy_utils::diagnostics::span_lint_and_then;
44
use clippy_utils::usage::mutated_variables;
55
use rustc_hir::def::{DefKind, Res};
@@ -10,7 +10,7 @@ use rustc_lint::LateContext;
1010
use std::ops::ControlFlow;
1111

1212
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, cond: &'tcx Expr<'_>, expr: &'tcx Expr<'_>) {
13-
if constant(cx, cx.typeck_results(), cond).is_some() {
13+
if ConstEvalCtxt::new(cx).eval(cond).is_some() {
1414
// A pure constant condition (e.g., `while false`) is not linted.
1515
return;
1616
}

clippy_lints/src/manual_clamp.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_config::msrvs::{self, Msrv};
22
use clippy_config::Conf;
3-
use clippy_utils::consts::{constant, Constant};
3+
use clippy_utils::consts::{ConstEvalCtxt, Constant};
44
use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then};
55
use clippy_utils::higher::If;
66
use clippy_utils::sugg::Sugg;
@@ -122,8 +122,9 @@ impl<'tcx> ClampSuggestion<'tcx> {
122122
if max_type != min_type {
123123
return false;
124124
}
125-
if let Some(max) = constant(cx, cx.typeck_results(), self.params.max)
126-
&& let Some(min) = constant(cx, cx.typeck_results(), self.params.min)
125+
let ecx = ConstEvalCtxt::new(cx);
126+
if let Some(max) = ecx.eval(self.params.max)
127+
&& let Some(min) = ecx.eval(self.params.min)
127128
&& let Some(ord) = Constant::partial_cmp(cx.tcx, max_type, &min, &max)
128129
{
129130
ord != Ordering::Greater

clippy_lints/src/manual_float_methods.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::consts::{constant, Constant};
1+
use clippy_utils::consts::{ConstEvalCtxt, Constant};
22
use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::source::snippet_opt;
44
use clippy_utils::{is_from_proc_macro, path_to_local};
@@ -95,8 +95,9 @@ impl<'tcx> LateLintPass<'tcx> for ManualFloatMethods {
9595
|| cx.tcx.features().declared(sym!(const_float_classify))
9696
)
9797
&& let [first, second, const_1, const_2] = exprs
98-
&& let Some(const_1) = constant(cx, cx.typeck_results(), const_1)
99-
&& let Some(const_2) = constant(cx, cx.typeck_results(), const_2)
98+
&& let ecx = ConstEvalCtxt::new(cx)
99+
&& let Some(const_1) = ecx.eval(const_1)
100+
&& let Some(const_2) = ecx.eval(const_2)
100101
&& path_to_local(first).is_some_and(|f| path_to_local(second).is_some_and(|s| f == s))
101102
// The actual infinity check, we also allow `NEG_INFINITY` before` INFINITY` just in
102103
// case somebody does that for some reason

clippy_lints/src/manual_rem_euclid.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_config::msrvs::{self, Msrv};
22
use clippy_config::Conf;
3-
use clippy_utils::consts::{constant_full_int, FullInt};
3+
use clippy_utils::consts::{ConstEvalCtxt, FullInt};
44
use clippy_utils::diagnostics::span_lint_and_sugg;
55
use clippy_utils::source::snippet_with_context;
66
use clippy_utils::{in_constant, path_to_local};
@@ -117,7 +117,7 @@ fn check_for_either_unsigned_int_constant<'a>(
117117
}
118118

119119
fn check_for_unsigned_int_constant<'a>(cx: &'a LateContext<'_>, expr: &'a Expr<'_>) -> Option<u128> {
120-
let int_const = constant_full_int(cx, cx.typeck_results(), expr)?;
120+
let int_const = ConstEvalCtxt::new(cx).eval_full_int(expr)?;
121121
match int_const {
122122
FullInt::S(s) => s.try_into().ok(),
123123
FullInt::U(u) => Some(u),

clippy_lints/src/manual_rotate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::fmt::Display;
22

3-
use clippy_utils::consts::{constant, Constant};
3+
use clippy_utils::consts::{ConstEvalCtxt, Constant};
44
use clippy_utils::diagnostics::span_lint_and_sugg;
55
use clippy_utils::sugg;
66
use rustc_errors::Applicability;
@@ -66,7 +66,7 @@ fn parse_shift<'tcx>(
6666
BinOpKind::Shr => ShiftDirection::Right,
6767
_ => return None,
6868
};
69-
let const_expr = constant(cx, cx.typeck_results(), r)?;
69+
let const_expr = ConstEvalCtxt::new(cx).eval(r)?;
7070
if let Constant::Int(shift) = const_expr {
7171
return Some((dir, shift, l));
7272
}

clippy_lints/src/manual_strip.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_config::msrvs::{self, Msrv};
22
use clippy_config::Conf;
3-
use clippy_utils::consts::{constant, Constant};
3+
use clippy_utils::consts::{ConstEvalCtxt, Constant};
44
use clippy_utils::diagnostics::span_lint_and_then;
55
use clippy_utils::source::snippet;
66
use clippy_utils::usage::mutated_variables;
@@ -147,7 +147,7 @@ fn len_arg<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx E
147147

148148
// Returns the length of the `expr` if it's a constant string or char.
149149
fn constant_length(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<u128> {
150-
let value = constant(cx, cx.typeck_results(), expr)?;
150+
let value = ConstEvalCtxt::new(cx).eval(expr)?;
151151
match value {
152152
Constant::Str(value) => Some(value.len() as u128),
153153
Constant::Char(value) => Some(value.len_utf8() as u128),

0 commit comments

Comments
 (0)