Skip to content

Commit 462de51

Browse files
authored
Merge pull request #367 from tgross35/type-helpers
Introduce helper types for accessing trait items
2 parents 78a9394 + c07e157 commit 462de51

File tree

6 files changed

+23
-5
lines changed

6 files changed

+23
-5
lines changed

libm/crates/libm-test/benches/random.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ macro_rules! musl_rand_benches {
2626

2727
#[cfg(feature = "build-musl")]
2828
let musl_extra = MuslExtra {
29-
musl_fn: Some(musl_math_sys::$fn_name as <Op as MathOp>::CFn),
29+
musl_fn: Some(musl_math_sys::$fn_name as libm_test::CFn<Op>),
3030
skip_on_i586: $skip_on_i586
3131
};
3232

libm/crates/libm-test/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ pub mod op;
55
mod precision;
66
mod test_traits;
77

8-
pub use libm::support::{Float, Int};
9-
pub use op::{BaseName, Identifier, MathOp};
8+
pub use libm::support::{Float, Int, IntTy};
9+
pub use op::{BaseName, CFn, FTy, Identifier, MathOp, RustFn, RustRet};
1010
pub use precision::{MaybeOverride, SpecialCase, default_ulp};
1111
pub use test_traits::{CheckBasis, CheckCtx, CheckOutput, GenerateInput, Hex, TupleCall};
1212

libm/crates/libm-test/src/op.rs

+9
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ pub trait MathOp {
7070
const ROUTINE: Self::RustFn;
7171
}
7272

73+
/// Access the associated `FTy` type from an op (helper to avoid ambiguous associated types).
74+
pub type FTy<Op> = <Op as MathOp>::FTy;
75+
/// Access the associated `CFn` type from an op (helper to avoid ambiguous associated types).
76+
pub type CFn<Op> = <Op as MathOp>::CFn;
77+
/// Access the associated `RustFn` type from an op (helper to avoid ambiguous associated types).
78+
pub type RustFn<Op> = <Op as MathOp>::RustFn;
79+
/// Access the associated `RustRet` type from an op (helper to avoid ambiguous associated types).
80+
pub type RustRet<Op> = <Op as MathOp>::RustRet;
81+
7382
macro_rules! do_thing {
7483
// Matcher for unary functions
7584
(

libm/src/math/support/float_traits.rs

+4
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ pub trait Float:
153153
}
154154
}
155155

156+
/// Access the associated `Int` type from a float (helper to avoid ambiguous associated types).
157+
#[allow(dead_code)]
158+
pub type IntTy<F> = <F as Float>::Int;
159+
156160
macro_rules! float_impl {
157161
($ty:ident, $ity:ident, $sity:ident, $expty:ident, $bits:expr, $significand_bits:expr) => {
158162
impl Float for $ty {

libm/src/math/support/int_traits.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ pub trait MinInt:
2626
const MAX: Self;
2727
}
2828

29+
/// Access the associated `OtherSign` type from an int (helper to avoid ambiguous associated
30+
/// types).
31+
pub type OtherSign<I> = <I as MinInt>::OtherSign;
32+
2933
/// Trait for some basic operations on integers
3034
#[allow(dead_code)]
3135
pub trait Int:
@@ -53,7 +57,7 @@ pub trait Int:
5357
+ CastInto<usize>
5458
+ CastFrom<u8>
5559
{
56-
fn signed(self) -> <Self::Unsigned as MinInt>::OtherSign;
60+
fn signed(self) -> OtherSign<Self::Unsigned>;
5761
fn unsigned(self) -> Self::Unsigned;
5862
fn from_unsigned(unsigned: Self::Unsigned) -> Self;
5963
fn abs(self) -> Self;

libm/src/math/support/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ mod float_traits;
44
mod hex_float;
55
mod int_traits;
66

7-
pub use float_traits::Float;
7+
#[allow(unused_imports)]
8+
pub use float_traits::{Float, IntTy};
89
#[allow(unused_imports)]
910
pub use hex_float::{hf32, hf64};
1011
pub use int_traits::{CastFrom, CastInto, DInt, HInt, Int, MinInt};

0 commit comments

Comments
 (0)