Should I trust the compiler to replace &T with T in function arguments when T is small enough? (for static dispatch)

⚓ Rust    📅 2025-09-20    👤 surdeus    👁️ 7      

surdeus

Warning

This post was published 42 days ago. The information described in this article may have changed.

Like if I use this example function (not a real life scenario, just an example) for f64 or f32 will it still take pointers to f64 even in the release build?

add<N>(lhs: &N, rhs: &N) -> N where N: Add<&N, Output=N>;

I hope this explanation of my question was sufficient, but for anyone curious I'm thinking of removing this associated type which defined the type to be used in function arguments. I want to remove it because it historically has been a source of very strange lifetime errors and weird workarounds (this one is for simulating covariance). Since f64 is what I think will be used often with my library, I won't undo this solution if I can't trust the compiler to replace &f64 with f64.

1 post - 1 participant

Read full topic

🏷️ Rust_feed