Skip to content

Commit 4653a8b

Browse files
committed
Restore removed code and mark it for usage in stage0
The old code is temporarily needed in order to keep the MSVC build working. It should be possible to remove this code after the bootstrap compiler is updated to contain the MSVC workaround from #27875.
1 parent 152c76e commit 4653a8b

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/libcore/ops.rs

+41
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ macro_rules! rem_impl_integer {
441441

442442
rem_impl_integer! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
443443

444+
#[cfg(not(stage0))]
444445
macro_rules! rem_impl_float {
445446
($($t:ty)*) => ($(
446447
#[stable(feature = "rust1", since = "1.0.0")]
@@ -455,8 +456,48 @@ macro_rules! rem_impl_float {
455456
)*)
456457
}
457458

459+
#[cfg(not(stage0))]
458460
rem_impl_float! { f32 f64 }
459461

462+
#[stable(feature = "rust1", since = "1.0.0")]
463+
#[cfg(stage0)]
464+
impl Rem for f32 {
465+
type Output = f32;
466+
467+
// The builtin f32 rem operator is broken when targeting
468+
// MSVC; see comment in std::f32::floor.
469+
// FIXME: See also #27859.
470+
#[inline]
471+
#[cfg(target_env = "msvc")]
472+
fn rem(self, other: f32) -> f32 {
473+
(self as f64).rem(other as f64) as f32
474+
}
475+
476+
#[inline]
477+
#[cfg(not(target_env = "msvc"))]
478+
fn rem(self, other: f32) -> f32 {
479+
extern { fn fmodf(a: f32, b: f32) -> f32; }
480+
unsafe { fmodf(self, other) }
481+
}
482+
}
483+
484+
#[stable(feature = "rust1", since = "1.0.0")]
485+
#[cfg(stage0)]
486+
impl Rem for f64 {
487+
type Output = f64;
488+
489+
#[inline]
490+
fn rem(self, other: f64) -> f64 {
491+
extern { fn fmod(a: f64, b: f64) -> f64; }
492+
unsafe { fmod(self, other) }
493+
}
494+
}
495+
496+
#[cfg(stage0)]
497+
forward_ref_binop! { impl Rem, rem for f64, f64 }
498+
#[cfg(stage0)]
499+
forward_ref_binop! { impl Rem, rem for f32, f32 }
500+
460501
/// The `Neg` trait is used to specify the functionality of unary `-`.
461502
///
462503
/// # Examples

0 commit comments

Comments
 (0)