diff options
Diffstat (limited to 'compiler/rustc_middle/src/ty/layout.rs')
| -rw-r--r-- | compiler/rustc_middle/src/ty/layout.rs | 27 |
1 files changed, 23 insertions, 4 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"), } } } |
