Skip to content

Commit 57a21a1

Browse files
committed
Remove or reduce the scope of allow(unused) where possible
Now that we have more in this crate making use of traits, try to be more specific about what is actually unused.
1 parent faa3f43 commit 57a21a1

File tree

5 files changed

+20
-29
lines changed

5 files changed

+20
-29
lines changed

crates/libm-macros/tests/basic.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,14 @@ macro_rules! basic {
1818
fn_extra: $fn_extra:expr,
1919
) => {
2020
$(#[$attr])*
21-
mod $fn_name {
22-
#[allow(unused)]
21+
#[allow(dead_code)]
22+
pub mod $fn_name {
2323
type FTy= $FTy;
24-
#[allow(unused)]
2524
type CFnTy<'a> = $CFn;
26-
#[allow(unused)]
2725
type RustFnTy = $RustFn;
28-
#[allow(unused)]
2926
type RustArgsTy = $RustArgs;
30-
#[allow(unused)]
3127
type RustRetTy = $RustRet;
32-
#[allow(unused)]
3328
const A: &[&str] = &[$($extra_tt)*];
34-
#[allow(unused)]
3529
fn foo(a: f32) -> f32 {
3630
$fn_extra(a)
3731
}
@@ -92,10 +86,9 @@ macro_rules! specified_types {
9286
attrs: [$($attr:meta),*],
9387
) => {
9488
$(#[$attr])*
89+
#[allow(dead_code)]
9590
mod $fn_name {
96-
#[allow(unused)]
9791
type RustFnTy = $RustFn;
98-
#[allow(unused)]
9992
type RustArgsTy = $RustArgs;
10093
}
10194
};

src/math/support/big.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
//! Integers used for wide operations, larger than `u128`.
22
3-
#![allow(unused)]
4-
53
#[cfg(test)]
64
mod tests;
75

8-
use core::{fmt, ops};
6+
use core::ops;
97

108
use super::{DInt, HInt, Int, MinInt};
119

1210
const WORD_LO_MASK: u64 = 0x00000000ffffffff;
1311
const WORD_HI_MASK: u64 = 0xffffffff00000000;
1412
const WORD_FULL_MASK: u64 = 0xffffffffffffffff;
1513
const U128_LO_MASK: u128 = u64::MAX as u128;
16-
const U128_HI_MASK: u128 = (u64::MAX as u128) << 64;
1714

1815
/// A 256-bit unsigned integer represented as 4 64-bit limbs.
1916
///
@@ -23,6 +20,7 @@ const U128_HI_MASK: u128 = (u64::MAX as u128) << 64;
2320
pub struct u256(pub [u64; 4]);
2421

2522
impl u256 {
23+
#[cfg(test)]
2624
pub const MAX: Self = Self([u64::MAX, u64::MAX, u64::MAX, u64::MAX]);
2725

2826
/// Reinterpret as a signed integer
@@ -40,6 +38,7 @@ pub struct i256(pub [u64; 4]);
4038

4139
impl i256 {
4240
/// Reinterpret as an unsigned integer
41+
#[cfg(test)]
4342
pub fn unsigned(self) -> u256 {
4443
u256(self.0)
4544
}
@@ -96,7 +95,7 @@ macro_rules! impl_common {
9695
impl ops::Shl<u32> for $ty {
9796
type Output = Self;
9897

99-
fn shl(self, rhs: u32) -> Self::Output {
98+
fn shl(self, _rhs: u32) -> Self::Output {
10099
unimplemented!("only used to meet trait bounds")
101100
}
102101
}
@@ -256,7 +255,7 @@ impl HInt for i128 {
256255
self.unsigned().zero_widen_mul(rhs.unsigned()).signed()
257256
}
258257

259-
fn widen_mul(self, rhs: Self) -> Self::D {
258+
fn widen_mul(self, _rhs: Self) -> Self::D {
260259
unimplemented!("signed i128 widening multiply is not used")
261260
}
262261

src/math/support/float_traits.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::{fmt, mem, ops};
33
use super::int_traits::{CastFrom, Int, MinInt};
44

55
/// Trait for some basic operations on floats
6-
#[allow(dead_code)]
6+
// #[allow(dead_code)]
77
pub trait Float:
88
Copy
99
+ fmt::Debug
@@ -84,11 +84,13 @@ pub trait Float:
8484
fn to_bits(self) -> Self::Int;
8585

8686
/// Returns `self` transmuted to `Self::SignedInt`
87+
#[allow(dead_code)]
8788
fn to_bits_signed(self) -> Self::SignedInt {
8889
self.to_bits().signed()
8990
}
9091

9192
/// Check bitwise equality.
93+
#[allow(dead_code)]
9294
fn biteq(self, rhs: Self) -> bool {
9395
self.to_bits() == rhs.to_bits()
9496
}
@@ -98,6 +100,7 @@ pub trait Float:
98100
///
99101
/// This method returns `true` if two NaNs are compared. Use [`biteq`](Self::biteq) instead
100102
/// if `NaN` should not be treated separately.
103+
#[allow(dead_code)]
101104
fn eq_repr(self, rhs: Self) -> bool {
102105
if self.is_nan() && rhs.is_nan() { true } else { self.biteq(rhs) }
103106
}
@@ -117,6 +120,7 @@ pub trait Float:
117120
}
118121

119122
/// Returns if `self` is subnormal.
123+
#[allow(dead_code)]
120124
fn is_subnormal(self) -> bool {
121125
(self.to_bits() & Self::EXP_MASK) == Self::Int::ZERO
122126
}
@@ -132,15 +136,11 @@ pub trait Float:
132136
}
133137

134138
/// Returns the significand with no implicit bit (or the "fractional" part)
139+
#[allow(dead_code)]
135140
fn frac(self) -> Self::Int {
136141
self.to_bits() & Self::SIG_MASK
137142
}
138143

139-
/// Returns the significand with implicit bit.
140-
fn imp_frac(self) -> Self::Int {
141-
self.frac() | Self::IMPLICIT_BIT
142-
}
143-
144144
/// Returns a `Self::Int` transmuted back to `Self`
145145
fn from_bits(a: Self::Int) -> Self;
146146

@@ -154,22 +154,25 @@ pub trait Float:
154154
)
155155
}
156156

157+
#[allow(dead_code)]
157158
fn abs(self) -> Self;
158159

159160
/// Returns a number composed of the magnitude of self and the sign of sign.
161+
#[allow(dead_code)]
160162
fn copysign(self, other: Self) -> Self;
161163

162164
/// Returns (normalized exponent, normalized significand)
165+
#[allow(dead_code)]
163166
fn normalize(significand: Self::Int) -> (i32, Self::Int);
164167

165168
/// Returns a number that represents the sign of self.
169+
#[allow(dead_code)]
166170
fn signum(self) -> Self {
167171
if self.is_nan() { self } else { Self::ONE.copysign(self) }
168172
}
169173
}
170174

171175
/// Access the associated `Int` type from a float (helper to avoid ambiguous associated types).
172-
#[allow(dead_code)]
173176
pub type IntTy<F> = <F as Float>::Int;
174177

175178
macro_rules! float_impl {

src/math/support/int_traits.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use core::{cmp, fmt, ops};
22

33
/// Minimal integer implementations needed on all integer types, including wide integers.
4-
#[allow(dead_code)]
54
pub trait MinInt:
65
Copy
76
+ fmt::Debug
@@ -261,7 +260,6 @@ int_impl!(i128, u128);
261260

262261
/// Trait for integers twice the bit width of another integer. This is implemented for all
263262
/// primitives except for `u8`, because there is not a smaller primitive.
264-
#[allow(unused)]
265263
pub trait DInt: MinInt {
266264
/// Integer that is half the bit width of the integer this trait is implemented for
267265
type H: HInt<D = Self>;
@@ -275,14 +273,14 @@ pub trait DInt: MinInt {
275273
(self.lo(), self.hi())
276274
}
277275
/// Constructs an integer using lower and higher half parts
276+
#[allow(unused)]
278277
fn from_lo_hi(lo: Self::H, hi: Self::H) -> Self {
279278
lo.zero_widen() | hi.widen_hi()
280279
}
281280
}
282281

283282
/// Trait for integers half the bit width of another integer. This is implemented for all
284283
/// primitives except for `u128`, because it there is not a larger primitive.
285-
#[allow(unused)]
286284
pub trait HInt: Int {
287285
/// Integer that is double the bit width of the integer this trait is implemented for
288286
type D: DInt<H = Self> + MinInt;
@@ -297,6 +295,7 @@ pub trait HInt: Int {
297295
/// around problems with associated type bounds (such as `Int<Othersign: DInt>`) being unstable
298296
fn zero_widen(self) -> Self::D;
299297
/// Widens the integer to have double bit width and shifts the integer into the higher bits
298+
#[allow(unused)]
300299
fn widen_hi(self) -> Self::D;
301300
/// Widening multiplication with zero widening. This cannot overflow.
302301
fn zero_widen_mul(self, rhs: Self) -> Self::D;
@@ -360,7 +359,6 @@ impl_h_int!(
360359
);
361360

362361
/// Trait to express (possibly lossy) casting of integers
363-
#[allow(unused)]
364362
pub trait CastInto<T: Copy>: Copy {
365363
/// By default, casts should be exact.
366364
fn cast(self) -> T;
@@ -369,7 +367,6 @@ pub trait CastInto<T: Copy>: Copy {
369367
fn cast_lossy(self) -> T;
370368
}
371369

372-
#[allow(unused)]
373370
pub trait CastFrom<T: Copy>: Copy {
374371
/// By default, casts should be exact.
375372
fn cast_from(value: T) -> Self;

src/math/support/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ mod float_traits;
55
pub mod hex_float;
66
mod int_traits;
77

8-
#[allow(unused_imports)]
98
pub use float_traits::{Float, IntTy};
109
pub(crate) use float_traits::{f32_from_bits, f64_from_bits};
1110
#[cfg(f16_enabled)]

0 commit comments

Comments
 (0)