Skip to content

Commit 51b0d4a

Browse files
committed
Rustc changes
cc rust-lang/rust#77227
1 parent c2cf40c commit 51b0d4a

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

clippy_lints/src/consts.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ use rustc_data_structures::sync::Lrc;
77
use rustc_hir::def::{DefKind, Res};
88
use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, QPath, UnOp};
99
use rustc_lint::LateContext;
10+
use rustc_middle::mir::interpret::Scalar;
1011
use rustc_middle::ty::subst::{Subst, SubstsRef};
11-
use rustc_middle::ty::{self, Ty, TyCtxt};
12+
use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt};
1213
use rustc_middle::{bug, span_bug};
1314
use rustc_span::symbol::Symbol;
1415
use std::cmp::Ordering::{self, Equal};
@@ -500,21 +501,21 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
500501
}
501502

502503
pub fn miri_to_const(result: &ty::Const<'_>) -> Option<Constant> {
503-
use rustc_middle::mir::interpret::{ConstValue, Scalar};
504+
use rustc_middle::mir::interpret::ConstValue;
504505
match result.val {
505-
ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data: d, .. })) => {
506+
ty::ConstKind::Value(ConstValue::Scalar(Scalar::Int(int))) => {
506507
match result.ty.kind() {
507-
ty::Bool => Some(Constant::Bool(d == 1)),
508-
ty::Uint(_) | ty::Int(_) => Some(Constant::Int(d)),
508+
ty::Bool => Some(Constant::Bool(int == ScalarInt::TRUE)),
509+
ty::Uint(_) | ty::Int(_) => Some(Constant::Int(int.assert_bits(int.size()))),
509510
ty::Float(FloatTy::F32) => Some(Constant::F32(f32::from_bits(
510-
d.try_into().expect("invalid f32 bit representation"),
511+
int.try_into().expect("invalid f32 bit representation"),
511512
))),
512513
ty::Float(FloatTy::F64) => Some(Constant::F64(f64::from_bits(
513-
d.try_into().expect("invalid f64 bit representation"),
514+
int.try_into().expect("invalid f64 bit representation"),
514515
))),
515516
ty::RawPtr(type_and_mut) => {
516517
if let ty::Uint(_) = type_and_mut.ty.kind() {
517-
return Some(Constant::RawPtr(d));
518+
return Some(Constant::RawPtr(int.assert_bits(int.size())));
518519
}
519520
None
520521
},

0 commit comments

Comments
 (0)