X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=clippy_lints%2Fsrc%2Fconsts.rs;h=c64c00134e89a1e77dadadf5bc306c536aa1b45d;hb=2153abb4124fd3dca018d4adb4e79693f1a9fedd;hp=b1d540c9751589a600b3477dd75320fb56bf7fe7;hpb=563da5248d867e7147b084161bee040a241a7419;p=rust.git diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index b1d540c9751..c64c00134e8 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -492,6 +492,41 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option { }, _ => None, }, + ty::ConstKind::Value(ConstValue::ByRef { alloc, offset: _ }) => match result.ty.kind { + ty::Array(sub_type, len) => match sub_type.kind { + ty::Float(FloatTy::F32) => match miri_to_const(len) { + Some(Constant::Int(len)) => alloc + .inspect_with_undef_and_ptr_outside_interpreter(0..(4 * len as usize)) + .to_owned() + .chunks(4) + .map(|chunk| { + Some(Constant::F32(f32::from_le_bytes( + chunk.try_into().expect("this shouldn't happen"), + ))) + }) + .collect::>>() + .map(Constant::Vec), + _ => None, + }, + ty::Float(FloatTy::F64) => match miri_to_const(len) { + Some(Constant::Int(len)) => alloc + .inspect_with_undef_and_ptr_outside_interpreter(0..(8 * len as usize)) + .to_owned() + .chunks(8) + .map(|chunk| { + Some(Constant::F64(f64::from_le_bytes( + chunk.try_into().expect("this shouldn't happen"), + ))) + }) + .collect::>>() + .map(Constant::Vec), + _ => None, + }, + // FIXME: implement other array type conversions. + _ => None, + }, + _ => None, + }, // FIXME: implement other conversions. _ => None, }