Skip to content

Commit 84e935b

Browse files
committed
Assume has_div_euclid
1 parent 8a59e17 commit 84e935b

File tree

2 files changed

+7
-116
lines changed

2 files changed

+7
-116
lines changed

build.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ use std::env;
33
fn main() {
44
let ac = autocfg::new();
55

6-
ac.emit_expression_cfg("1u32.div_euclid(1u32)", "has_div_euclid");
7-
86
if env::var_os("CARGO_FEATURE_STD").is_some() {
97
ac.emit_expression_cfg("1f64.copysign(-1f64)", "has_copysign");
108
}

src/ops/euclid.rs

Lines changed: 7 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ pub trait Euclid: Sized + Div<Self, Output = Self> + Rem<Self, Output = Self> {
7171

7272
macro_rules! euclid_forward_impl {
7373
($($t:ty)*) => {$(
74-
#[cfg(has_div_euclid)]
7574
impl Euclid for $t {
7675
#[inline]
7776
fn div_euclid(&self, v: &$t) -> Self {
@@ -86,64 +85,13 @@ macro_rules! euclid_forward_impl {
8685
)*}
8786
}
8887

89-
macro_rules! euclid_int_impl {
90-
($($t:ty)*) => {$(
91-
euclid_forward_impl!($t);
92-
93-
#[cfg(not(has_div_euclid))]
94-
impl Euclid for $t {
95-
#[inline]
96-
fn div_euclid(&self, v: &$t) -> Self {
97-
let q = self / v;
98-
if self % v < 0 {
99-
return if *v > 0 { q - 1 } else { q + 1 }
100-
}
101-
q
102-
}
103-
104-
#[inline]
105-
fn rem_euclid(&self, v: &$t) -> Self {
106-
let r = self % v;
107-
if r < 0 {
108-
if *v < 0 {
109-
r - v
110-
} else {
111-
r + v
112-
}
113-
} else {
114-
r
115-
}
116-
}
117-
}
118-
)*}
119-
}
88+
euclid_forward_impl!(isize i8 i16 i32 i64 i128);
89+
euclid_forward_impl!(usize u8 u16 u32 u64 u128);
12090

121-
macro_rules! euclid_uint_impl {
122-
($($t:ty)*) => {$(
123-
euclid_forward_impl!($t);
124-
125-
#[cfg(not(has_div_euclid))]
126-
impl Euclid for $t {
127-
#[inline]
128-
fn div_euclid(&self, v: &$t) -> Self {
129-
self / v
130-
}
131-
132-
#[inline]
133-
fn rem_euclid(&self, v: &$t) -> Self {
134-
self % v
135-
}
136-
}
137-
)*}
138-
}
139-
140-
euclid_int_impl!(isize i8 i16 i32 i64 i128);
141-
euclid_uint_impl!(usize u8 u16 u32 u64 u128);
142-
143-
#[cfg(all(has_div_euclid, feature = "std"))]
91+
#[cfg(feature = "std")]
14492
euclid_forward_impl!(f32 f64);
14593

146-
#[cfg(not(all(has_div_euclid, feature = "std")))]
94+
#[cfg(not(feature = "std"))]
14795
impl Euclid for f32 {
14896
#[inline]
14997
fn div_euclid(&self, v: &f32) -> f32 {
@@ -165,7 +113,7 @@ impl Euclid for f32 {
165113
}
166114
}
167115

168-
#[cfg(not(all(has_div_euclid, feature = "std")))]
116+
#[cfg(not(feature = "std"))]
169117
impl Euclid for f64 {
170118
#[inline]
171119
fn div_euclid(&self, v: &f64) -> f64 {
@@ -219,7 +167,6 @@ pub trait CheckedEuclid: Euclid {
219167

220168
macro_rules! checked_euclid_forward_impl {
221169
($($t:ty)*) => {$(
222-
#[cfg(has_div_euclid)]
223170
impl CheckedEuclid for $t {
224171
#[inline]
225172
fn checked_div_euclid(&self, v: &$t) -> Option<Self> {
@@ -234,62 +181,8 @@ macro_rules! checked_euclid_forward_impl {
234181
)*}
235182
}
236183

237-
macro_rules! checked_euclid_int_impl {
238-
($($t:ty)*) => {$(
239-
checked_euclid_forward_impl!($t);
240-
241-
#[cfg(not(has_div_euclid))]
242-
impl CheckedEuclid for $t {
243-
#[inline]
244-
fn checked_div_euclid(&self, v: &$t) -> Option<$t> {
245-
if *v == 0 || (*self == Self::min_value() && *v == -1) {
246-
None
247-
} else {
248-
Some(Euclid::div_euclid(self, v))
249-
}
250-
}
251-
252-
#[inline]
253-
fn checked_rem_euclid(&self, v: &$t) -> Option<$t> {
254-
if *v == 0 || (*self == Self::min_value() && *v == -1) {
255-
None
256-
} else {
257-
Some(Euclid::rem_euclid(self, v))
258-
}
259-
}
260-
}
261-
)*}
262-
}
263-
264-
macro_rules! checked_euclid_uint_impl {
265-
($($t:ty)*) => {$(
266-
checked_euclid_forward_impl!($t);
267-
268-
#[cfg(not(has_div_euclid))]
269-
impl CheckedEuclid for $t {
270-
#[inline]
271-
fn checked_div_euclid(&self, v: &$t) -> Option<$t> {
272-
if *v == 0 {
273-
None
274-
} else {
275-
Some(Euclid::div_euclid(self, v))
276-
}
277-
}
278-
279-
#[inline]
280-
fn checked_rem_euclid(&self, v: &$t) -> Option<$t> {
281-
if *v == 0 {
282-
None
283-
} else {
284-
Some(Euclid::rem_euclid(self, v))
285-
}
286-
}
287-
}
288-
)*}
289-
}
290-
291-
checked_euclid_int_impl!(isize i8 i16 i32 i64 i128);
292-
checked_euclid_uint_impl!(usize u8 u16 u32 u64 u128);
184+
checked_euclid_forward_impl!(isize i8 i16 i32 i64 i128);
185+
checked_euclid_forward_impl!(usize u8 u16 u32 u64 u128);
293186

294187
#[cfg(test)]
295188
mod tests {

0 commit comments

Comments
 (0)