about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTrevor Gross <tmgross@umich.edu>2024-03-26 05:22:18 -0400
committerTrevor Gross <tmgross@umich.edu>2024-03-28 15:02:51 -0400
commitd7d5fc97341ebc127ad716053c3efe6e613ba3a7 (patch)
tree2a8f64cdbd9e93fbcfa21fd20872e060383341e9
parentc5e7f45b6219a963e8e27ef6e15587f22e80a3f5 (diff)
downloadrust-d7d5fc97341ebc127ad716053c3efe6e613ba3a7.tar.gz
rust-d7d5fc97341ebc127ad716053c3efe6e613ba3a7.zip
Add basic trait impls for `f16` and `f128`
Split off part of <https://github.com/rust-lang/rust/pull/122470> so the
compiler doesn't ICE because it expects primitives to have some minimal
traits.

Fixes <https://github.com/rust-lang/rust/issues/123074>
-rw-r--r--library/core/src/clone.rs2
-rw-r--r--library/core/src/cmp.rs4
-rw-r--r--library/core/src/default.rs4
-rw-r--r--library/core/src/lib.rs2
-rw-r--r--library/core/src/marker.rs2
-rw-r--r--tests/ui/binop/binary-op-suggest-deref.stderr6
-rw-r--r--tests/ui/mismatched_types/binops.stderr12
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<Foo>` is not implemented for `&&{integer}`
    = help: the following other types implement trait `PartialEq<Rhs>`:
+             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<String>` is not implemented for `{integer}`
    = help: the following other types implement trait `PartialOrd<Rhs>`:
+             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<Result<{integer}, _>>` is not implemented for `{integer}`
    = help: the following other types implement trait `PartialEq<Rhs>`:
+             f128
+             f16
              f32
              f64
              i128
              i16
              i32
              i64
-             i8
-             isize
-           and 6 others
+           and 8 others
 
 error: aborting due to 6 previous errors