Skip to content

Commit 6d94f95

Browse files
committed
address review
1 parent 3f4ad95 commit 6d94f95

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

clippy_lints/src/enum_clike.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant {
5050
.tcx
5151
.const_eval_poly(def_id.to_def_id())
5252
.ok()
53-
.and_then(|val| Some(rustc_middle::mir::ConstantKind::from_value(val, ty)));
53+
.map(|val| rustc_middle::mir::ConstantKind::from_value(val, ty));
5454
if let Some(Constant::Int(val)) = constant.and_then(|c| miri_to_const(cx.tcx, c)) {
5555
if let ty::Adt(adt, _) = ty.kind() {
5656
if adt.is_enum() {

clippy_utils/src/consts.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
430430
None,
431431
)
432432
.ok()
433-
.and_then(|val| Some(rustc_middle::mir::ConstantKind::from_value(val, ty)))?;
433+
.map(|val| rustc_middle::mir::ConstantKind::from_value(val, ty))?;
434434
let result = miri_to_const(self.lcx.tcx, result);
435435
if result.is_some() {
436436
self.needed_resolution = true;
@@ -581,16 +581,6 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
581581
}
582582
}
583583

584-
fn try_const_to_constant<'tcx>(tcx: TyCtxt<'tcx>, c: ty::Const<'tcx>) -> Option<Constant> {
585-
match c.kind() {
586-
ty::ConstKind::Value(valtree) => {
587-
let const_val = tcx.valtree_to_const_val((c.ty(), valtree));
588-
miri_to_const(tcx, mir::ConstantKind::from_value(const_val, c.ty()))
589-
},
590-
_ => None,
591-
}
592-
}
593-
594584
pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) -> Option<Constant> {
595585
use rustc_middle::mir::interpret::ConstValue;
596586
match result {
@@ -629,8 +619,8 @@ pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) -
629619
},
630620
mir::ConstantKind::Val(ConstValue::ByRef { alloc, offset: _ }, _) => match result.ty().kind() {
631621
ty::Array(sub_type, len) => match sub_type.kind() {
632-
ty::Float(FloatTy::F32) => match try_const_to_constant(tcx, *len) {
633-
Some(Constant::Int(len)) => alloc
622+
ty::Float(FloatTy::F32) => match len.try_eval_usize(tcx, ty::ParamEnv::empty()) {
623+
Some(len) => alloc
634624
.inner()
635625
.inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * len as usize))
636626
.to_owned()
@@ -644,8 +634,8 @@ pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) -
644634
.map(Constant::Vec),
645635
_ => None,
646636
},
647-
ty::Float(FloatTy::F64) => match try_const_to_constant(tcx, *len) {
648-
Some(Constant::Int(len)) => alloc
637+
ty::Float(FloatTy::F64) => match len.try_eval_usize(tcx, ty::ParamEnv::empty()) {
638+
Some(len) => alloc
649639
.inner()
650640
.inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * len as usize))
651641
.to_owned()

0 commit comments

Comments
 (0)