diff options
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/ty/layout.rs | 27 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/util.rs | 7 |
2 files changed, 26 insertions, 8 deletions
diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index f8490e5e15f..eb5dfd4e0c0 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -114,16 +114,35 @@ impl Integer { } } -#[extension(pub trait PrimitiveExt)] -impl Primitive { +#[extension(pub trait FloatExt)] +impl Float { #[inline] fn to_ty<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { match *self { - Int(i, signed) => i.to_ty(tcx, signed), F16 => tcx.types.f16, F32 => tcx.types.f32, F64 => tcx.types.f64, F128 => tcx.types.f128, + } + } + + fn from_float_ty(fty: ty::FloatTy) -> Self { + match fty { + ty::FloatTy::F16 => F16, + ty::FloatTy::F32 => F32, + ty::FloatTy::F64 => F64, + ty::FloatTy::F128 => F128, + } + } +} + +#[extension(pub trait PrimitiveExt)] +impl Primitive { + #[inline] + fn to_ty<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { + match *self { + Int(i, signed) => i.to_ty(tcx, signed), + Float(f) => f.to_ty(tcx), // FIXME(erikdesjardins): handle non-default addrspace ptr sizes Pointer(_) => Ty::new_mut_ptr(tcx, tcx.types.unit), } @@ -140,7 +159,7 @@ impl Primitive { let signed = false; tcx.data_layout().ptr_sized_integer().to_ty(tcx, signed) } - F16 | F32 | F64 | F128 => bug!("floats do not have an int type"), + Float(_) => bug!("floats do not have an int type"), } } } diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index f5e973f85da..6ad4f492f74 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -2,7 +2,7 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; use crate::query::{IntoQueryParam, Providers}; -use crate::ty::layout::IntegerExt; +use crate::ty::layout::{FloatExt, IntegerExt}; use crate::ty::{ self, FallibleTypeFolder, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, @@ -20,7 +20,7 @@ use rustc_index::bit_set::GrowableBitSet; use rustc_macros::{extension, HashStable, TyDecodable, TyEncodable}; use rustc_session::Limit; use rustc_span::sym; -use rustc_target::abi::{Integer, IntegerType, Primitive, Size}; +use rustc_target::abi::{Float, Integer, IntegerType, Size}; use rustc_target::spec::abi::Abi; use smallvec::{smallvec, SmallVec}; use std::{fmt, iter}; @@ -1145,8 +1145,7 @@ impl<'tcx> Ty<'tcx> { ty::Char => Size::from_bytes(4), ty::Int(ity) => Integer::from_int_ty(&tcx, ity).size(), ty::Uint(uty) => Integer::from_uint_ty(&tcx, uty).size(), - ty::Float(ty::FloatTy::F32) => Primitive::F32.size(&tcx), - ty::Float(ty::FloatTy::F64) => Primitive::F64.size(&tcx), + ty::Float(fty) => Float::from_float_ty(fty).size(), _ => bug!("non primitive type"), } } |
