Skip to content

Commit

Permalink
Add basic trait impls for f16 and f128
Browse files Browse the repository at this point in the history
Split off part of <#122470> so the
compiler doesn't ICE because it expects primitives to have some minimal
traits.

Fixes <#123074>
  • Loading branch information
tgross35 committed Mar 28, 2024
1 parent c5e7f45 commit d7d5fc9
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion library/core/src/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions library/core/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -1539,7 +1539,7 @@ mod impls {
}
}

partial_ord_impl! { f32 f64 }
partial_ord_impl! { f16 f32 f64 f128 }

macro_rules! ord_impl {
($($t:ty)*) => ($(
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`" }
2 changes: 2 additions & 0 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/binop/binary-op-suggest-deref.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/mismatched_types/binops.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit d7d5fc9

Please sign in to comment.