diff options
| author | beetrees <b@beetr.ee> | 2024-05-06 13:27:40 +0100 |
|---|---|---|
| committer | beetrees <b@beetr.ee> | 2024-05-06 14:56:10 +0100 |
| commit | 3769fddba23985e9ab83828ccce672507e7dd891 (patch) | |
| tree | ec5cdc7c2024da713350fbccfa04ccb4cfd3b891 /compiler/rustc_middle/src/ty/layout.rs | |
| parent | 8cef37dbb67e9c80702925f19cf298c4203991e4 (diff) | |
| download | rust-3769fddba23985e9ab83828ccce672507e7dd891.tar.gz rust-3769fddba23985e9ab83828ccce672507e7dd891.zip | |
Refactor float `Primitive`s to a separate `Float` type
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"), } } } |
