Skip to content

core_float_math: Move functions to math folder #141282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

DJMcNab
Copy link
Contributor

@DJMcNab DJMcNab commented May 20, 2025

When these functions were added in #138087 It made a relatively common pattern for emulating these functions using an extension trait (which internally uses libm) much more fragile. If core::f32 happened to be imported by the user (to access a constant, say), then that import in the module namespace would take precedence over the f32 in the type namespace for resolving these functions, running headfirst into the stability attribute.

We ran into this in Color and chose to release the remedial 0.3.1 and 0.2.4, to allow downstream crates to build on docs.rs.

As these methods are perma-unstable, moving them into a new module should not have any long-term concerns, and ensures that this "breakage" doesn't adversely impact anyone else.

I believe that I've made the module unstable correctly. I presume that this does not require a test to make sure stable code can't depend on the module existing?

I've left the stability attribute on each function - happy to tweak this if a different pattern is more correct.

Tracking issue for core_float_math: #137578.
This PR is as requested in #138087.

r? @tgross35

Recommended reviewing with whitespace hidden.

(This is my first PR to std/core/this repository, as far as I can remember)

When these functions were added in
rust-lang#138087
It made a relatively common pattern for emulating
these functions using an extension trait (which
internally uses `libm`) much more fragile.
If `core::f32` happened to be imported by the user
(to access a constant, say), then that import in
the module namespace would take precedence over
`f32` in the type namespace for resolving these
functions, running headfirst into the stability
attribute.

We ran into this in Color -
https://github.com/linebender/color - and chose to
release the remedial 0.3.1 and 0.2.4, to allow
downstream crates to build on `docs.rs`.
As these methods are perma-unstable, moving them
into a new module should not have any long-term
concerns, and ensures that this breakage doesn't
adversely impact anyone else.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 20, 2025
@@ -1,3 +1,4 @@
use core::f64;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, these functions were actually testing the inherent methods on f64, as defined in std, rather than the functions from the f64 module.

Practically, that's the same thing, but the use of UFCS made that not clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants