Introduce helper types for accessing trait items

The ambiguous associated types error sometimes fires in cases where it
shouldn't be ambiguous ([1]), which can make things clunky when working
with chained associated types (e.g. `Op::FTy::Int::*` does not work).
Add helper types that we can use instead of the full syntax.

There aren't too many cases in-crate now but this is relevant for some
open PRs.

[1]: https://github.com/rust-lang/rust/issues/38078
This commit is contained in:
Trevor Gross
2024-12-22 23:15:16 +00:00
parent 97f4a0804e
commit 4cdb9ec674
6 changed files with 23 additions and 5 deletions

View File

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

View File

@@ -70,6 +70,15 @@ pub trait MathOp {
const ROUTINE: Self::RustFn;
}
/// Access the associated `FTy` type from an op (helper to avoid ambiguous associated types).
pub type FTy<Op> = <Op as MathOp>::FTy;
/// Access the associated `CFn` type from an op (helper to avoid ambiguous associated types).
pub type CFn<Op> = <Op as MathOp>::CFn;
/// Access the associated `RustFn` type from an op (helper to avoid ambiguous associated types).
pub type RustFn<Op> = <Op as MathOp>::RustFn;
/// Access the associated `RustRet` type from an op (helper to avoid ambiguous associated types).
pub type RustRet<Op> = <Op as MathOp>::RustRet;
macro_rules! do_thing {
// Matcher for unary functions
(