Skip to content

Commit 27634b0

Browse files
committed
Auto merge of rust-lang#94255 - b-naber:use-mir-constant-in-thir, r=oli-obk
Use mir constant in thir instead of ty::Const This is blocked on rust-lang#94059 (does include its changes, the first two commits in this PR correspond to those changes) and rust-lang#93800 being reinstated (which had to be reverted). Mainly opening since `@lcnr` offered to give some feedback and maybe also for a perf-run (if necessary). This currently contains a lot of duplication since some of the logic of `ty::Const` had to be copied to `mir::ConstantKind`, but with the introduction of valtrees a lot of that functionality will disappear from `ty::Const`. Only the last commit contains changes that need to be reviewed here. Did leave some `FIXME` comments regarding future implementation decisions and some things that might be incorrectly implemented. r? `@oli-obk`
2 parents 62d912e + 2f78075 commit 27634b0

File tree

3 files changed

+3
-5
lines changed

3 files changed

+3
-5
lines changed

clippy_lints/src/matches/overlapping_arms.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@ fn all_ranges<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>], ty: Ty<'tcx>)
4040
Some(rhs) => constant(cx, cx.typeck_results(), rhs)?.0,
4141
None => miri_to_const(ty.numeric_max_val(cx.tcx)?)?,
4242
};
43-
4443
let lhs_val = lhs_const.int_value(cx, ty)?;
4544
let rhs_val = rhs_const.int_value(cx, ty)?;
46-
4745
let rhs_bound = match range_end {
4846
RangeEnd::Included => EndBound::Included(rhs_val),
4947
RangeEnd::Excluded => EndBound::Excluded(rhs_val),

clippy_lints/src/neg_multiply.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for NegMultiply {
5353
fn check_mul(cx: &LateContext<'_>, span: Span, lit: &Expr<'_>, exp: &Expr<'_>) {
5454
if_chain! {
5555
if let ExprKind::Lit(ref l) = lit.kind;
56-
if consts::lit_to_constant(&l.node, cx.typeck_results().expr_ty_opt(lit)) == Constant::Int(1);
56+
if consts::lit_to_mir_constant(&l.node, cx.typeck_results().expr_ty_opt(lit)) == Constant::Int(1);
5757
if cx.typeck_results().expr_ty(exp).is_integral();
5858

5959
then {

clippy_utils/src/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl Constant {
179179
}
180180

181181
/// Parses a `LitKind` to a `Constant`.
182-
pub fn lit_to_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
182+
pub fn lit_to_mir_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
183183
match *lit {
184184
LitKind::Str(ref is, _) => Constant::Str(is.to_string()),
185185
LitKind::Byte(b) => Constant::Int(u128::from(b)),
@@ -301,7 +301,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
301301
if is_direct_expn_of(e.span, "cfg").is_some() {
302302
None
303303
} else {
304-
Some(lit_to_constant(&lit.node, self.typeck_results.expr_ty_opt(e)))
304+
Some(lit_to_mir_constant(&lit.node, self.typeck_results.expr_ty_opt(e)))
305305
}
306306
},
307307
ExprKind::Array(vec) => self.multi(vec).map(Constant::Vec),

0 commit comments

Comments
 (0)