From d7d5fc97341ebc127ad716053c3efe6e613ba3a7 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Tue, 26 Mar 2024 05:22:18 -0400 Subject: [PATCH] Add basic trait impls for `f16` and `f128` Split off part of so the compiler doesn't ICE because it expects primitives to have some minimal traits. Fixes --- library/core/src/clone.rs | 2 +- library/core/src/cmp.rs | 4 ++-- library/core/src/default.rs | 4 ++++ library/core/src/lib.rs | 2 ++ library/core/src/marker.rs | 2 +- tests/ui/binop/binary-op-suggest-deref.stderr | 6 +++--- tests/ui/mismatched_types/binops.stderr | 12 ++++++------ 7 files changed, 19 insertions(+), 13 deletions(-) diff --git a/library/core/src/clone.rs b/library/core/src/clone.rs index ba86334f950..d448c5338fc 100644 --- a/library/core/src/clone.rs +++ b/library/core/src/clone.rs @@ -227,7 +227,7 @@ mod impls { impl_clone! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 - f32 f64 + f16 f32 f64 f128 bool char } diff --git a/library/core/src/cmp.rs b/library/core/src/cmp.rs index a2f07814726..3567203384a 100644 --- a/library/core/src/cmp.rs +++ b/library/core/src/cmp.rs @@ -1486,7 +1486,7 @@ mod impls { } partial_eq_impl! { - bool char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 + bool char usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f64 f128 } macro_rules! eq_impl { @@ -1539,7 +1539,7 @@ mod impls { } } - partial_ord_impl! { f32 f64 } + partial_ord_impl! { f16 f32 f64 f128 } macro_rules! ord_impl { ($($t:ty)*) => ($( diff --git a/library/core/src/default.rs b/library/core/src/default.rs index a5075554682..e717a8d022f 100644 --- a/library/core/src/default.rs +++ b/library/core/src/default.rs @@ -178,5 +178,9 @@ default_impl! { i32, 0, "Returns the default value of `0`" } default_impl! { i64, 0, "Returns the default value of `0`" } default_impl! { i128, 0, "Returns the default value of `0`" } +#[cfg(not(bootstrap))] +default_impl! { f16, 0.0f16, "Returns the default value of `0.0`" } default_impl! { f32, 0.0f32, "Returns the default value of `0.0`" } default_impl! { f64, 0.0f64, "Returns the default value of `0.0`" } +#[cfg(not(bootstrap))] +default_impl! { f128, 0.0f128, "Returns the default value of `0.0`" } diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 3bc1a87f848..48251e5707b 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -229,6 +229,8 @@ #![feature(doc_notable_trait)] #![feature(effects)] #![feature(extern_types)] +#![feature(f128)] +#![feature(f16)] #![feature(freeze_impls)] #![feature(fundamental)] #![feature(generic_arg_infer)] diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index a56a2578c22..385c288db12 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -422,7 +422,7 @@ marker_impls! { Copy for usize, u8, u16, u32, u64, u128, isize, i8, i16, i32, i64, i128, - f32, f64, + f16, f32, f64, f128, bool, char, {T: ?Sized} *const T, {T: ?Sized} *mut T, diff --git a/tests/ui/binop/binary-op-suggest-deref.stderr b/tests/ui/binop/binary-op-suggest-deref.stderr index 32bd2554abb..47af51e2106 100644 --- a/tests/ui/binop/binary-op-suggest-deref.stderr +++ b/tests/ui/binop/binary-op-suggest-deref.stderr @@ -247,15 +247,15 @@ LL | _ = &&0 == Foo; | = help: the trait `PartialEq` is not implemented for `&&{integer}` = help: the following other types implement trait `PartialEq`: + f128 + f16 f32 f64 i128 i16 i32 i64 - i8 - isize - and 6 others + and 8 others error[E0369]: binary operation `==` cannot be applied to type `Foo` --> $DIR/binary-op-suggest-deref.rs:60:13 diff --git a/tests/ui/mismatched_types/binops.stderr b/tests/ui/mismatched_types/binops.stderr index 3585587ed4c..f8047c8e2d4 100644 --- a/tests/ui/mismatched_types/binops.stderr +++ b/tests/ui/mismatched_types/binops.stderr @@ -73,15 +73,15 @@ LL | 5 < String::new(); | = help: the trait `PartialOrd` is not implemented for `{integer}` = help: the following other types implement trait `PartialOrd`: + f128 + f16 f32 f64 i128 i16 i32 i64 - i8 - isize - and 6 others + and 8 others error[E0277]: can't compare `{integer}` with `Result<{integer}, _>` --> $DIR/binops.rs:7:7 @@ -91,15 +91,15 @@ LL | 6 == Ok(1); | = help: the trait `PartialEq>` is not implemented for `{integer}` = help: the following other types implement trait `PartialEq`: + f128 + f16 f32 f64 i128 i16 i32 i64 - i8 - isize - and 6 others + and 8 others error: aborting due to 6 previous errors