From 6d94f95a201582e6c99ffc54573cd06fdfd0c165 Mon Sep 17 00:00:00 2001 From: b-naber Date: Fri, 3 Jun 2022 20:42:35 +0200 Subject: [PATCH] address review --- clippy_lints/src/enum_clike.rs | 2 +- clippy_utils/src/consts.rs | 20 +++++--------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index b326d864d4b..da67888827d 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -50,7 +50,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { .tcx .const_eval_poly(def_id.to_def_id()) .ok() - .and_then(|val| Some(rustc_middle::mir::ConstantKind::from_value(val, ty))); + .map(|val| rustc_middle::mir::ConstantKind::from_value(val, ty)); if let Some(Constant::Int(val)) = constant.and_then(|c| miri_to_const(cx.tcx, c)) { if let ty::Adt(adt, _) = ty.kind() { if adt.is_enum() { diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs index ec323806fbf..6709ac13a43 100644 --- a/clippy_utils/src/consts.rs +++ b/clippy_utils/src/consts.rs @@ -430,7 +430,7 @@ fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'tcx>) -> Option, right: &Expr<'_>) -> Option(tcx: TyCtxt<'tcx>, c: ty::Const<'tcx>) -> Option { - match c.kind() { - ty::ConstKind::Value(valtree) => { - let const_val = tcx.valtree_to_const_val((c.ty(), valtree)); - miri_to_const(tcx, mir::ConstantKind::from_value(const_val, c.ty())) - }, - _ => None, - } -} - pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) -> Option { use rustc_middle::mir::interpret::ConstValue; match result { @@ -629,8 +619,8 @@ pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) - }, mir::ConstantKind::Val(ConstValue::ByRef { alloc, offset: _ }, _) => match result.ty().kind() { ty::Array(sub_type, len) => match sub_type.kind() { - ty::Float(FloatTy::F32) => match try_const_to_constant(tcx, *len) { - Some(Constant::Int(len)) => alloc + ty::Float(FloatTy::F32) => match len.try_eval_usize(tcx, ty::ParamEnv::empty()) { + Some(len) => alloc .inner() .inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * len as usize)) .to_owned() @@ -644,8 +634,8 @@ pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) - .map(Constant::Vec), _ => None, }, - ty::Float(FloatTy::F64) => match try_const_to_constant(tcx, *len) { - Some(Constant::Int(len)) => alloc + ty::Float(FloatTy::F64) => match len.try_eval_usize(tcx, ty::ParamEnv::empty()) { + Some(len) => alloc .inner() .inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * len as usize)) .to_owned()