Skip to content

fN::BITS constants for feature float_bits_const#151109

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
tyhdefu:float_bits_const
Feb 3, 2026
Merged

fN::BITS constants for feature float_bits_const#151109
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
tyhdefu:float_bits_const

Conversation

@tyhdefu
Copy link
Contributor

@tyhdefu tyhdefu commented Jan 14, 2026

Also enables the feature for compiler_builtins as otherwise this causes a warning and conflicts with the Float extension trait.


Implementation for #151073

Feature flag: #![feature(float_bits_const)]

Note that this is likely to conflict with some extension traits, as it has with compiler builtins. However, assuming correct values for the constants, they are either u32, the same type, which should not cause a problem (as shown by enabling the feature for compiler_builtins), or a different type (e.g. usize), which should cause a compiler error. Either way this should never change behaviour unless the extension trait implemented an incorrect value.

Also note that it doesn't seem to be possible to put multiple unstable attributes on an item, so f128::BITS and f16::BITS are gated behind the feature flags for those primitives, rather than #![feature(float_bits_const)]

@rustbot
Copy link
Collaborator

rustbot commented Jan 14, 2026

compiler-builtins is developed in its own repository. If possible, consider making this change to rust-lang/compiler-builtins instead.

cc @tgross35

@rustbot rustbot added A-compiler-builtins Area: compiler-builtins (https://github.com/rust-lang/compiler-builtins) 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 Jan 14, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 14, 2026

r? @scottmcm

rustbot has assigned @scottmcm.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@tyhdefu tyhdefu mentioned this pull request Jan 14, 2026
4 tasks
@rust-log-analyzer

This comment has been minimized.

@tyhdefu tyhdefu force-pushed the float_bits_const branch 2 times, most recently from 9a456a5 to 10e2d54 Compare January 14, 2026 16:20
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Jan 14, 2026

The Miri subtree was changed

cc @rust-lang/miri

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 15, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 15, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@tgross35
Copy link
Contributor

Note that this is likely to conflict with some extension traits, as it has with compiler builtins. However, assuming correct values for the constants, they are either u32, the same type, which should not cause a problem (as shown by enabling the feature for compiler_builtins), or a different type (e.g. usize), which should cause a compiler error. Either way this should never change behaviour unless the extension trait implemented an incorrect value.

Either of these things are unfortunately definitely a problem; we can't expect working crates to enable a nightly feature to keep building correctly, nor do we want them to stop building if the types don't line up. Not exactly sure what our options are here but let's start a crater run to have an idea of impact.

@bors try

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Jan 15, 2026
fN::BITS constants for feature float_bits_const
}

let fbits = <$fty>::BITS;
let fbits = <$fty as Float>::BITS;
Copy link
Member

Choose a reason for hiding this comment

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

This makes the BITS constant in the Float trait in this file dead, doesn't it?

Copy link
Contributor

Choose a reason for hiding this comment

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

The diff here I think is intentionally using BITS from the Float trait. It could go the other way and drop BITS from Flaot, just means Miri has to depend on this feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right - However when I tried to add the feature flag to the miri tests it said the feature was not allowed - I think it might be building these tests with a stable compiler that doesn't allow such features.

Regularly it would just be a warning but warnings are treated as errors, so I had to change this to get it to pass.

Copy link
Member

Choose a reason for hiding this comment

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

Miri uses the in-tree standard library built with the in-tree compiler. So it looks like something went wrong in your testing.

But anyway we still need the const in the trait since we have code generic over the trait, so it doesn't really matter.

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 15, 2026

☀️ Try build successful (CI)
Build commit: a3a8742 (a3a874232ae0a7586b5fbe7483c5a42e157bd62a, parent: a6acf0f07f0ed1c12e26dc0db3b9bf1d0504a0bb)

@rustbot
Copy link
Collaborator

rustbot commented Jan 15, 2026

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in check-cfg diagnostics

cc @Urgau

Some changes occurred to constck

cc @fee1-dead

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred in src/tools/opt-dist

cc @Kobzol

HIR ty lowering was modified

cc @fmease

Some changes occurred in GUI tests.

cc @GuillaumeGomez

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-CI Area: Our Github Actions CI A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-meta Area: Issues & PRs about the rust-lang/rust repository itself A-run-make Area: port run-make Makefiles to rmake.rs A-testsuite Area: The testsuite used to check the correctness of rustc labels Jan 15, 2026
@tgross35 tgross35 assigned tgross35 and unassigned joboet Jan 22, 2026
@craterbot
Copy link
Collaborator

🚧 Experiment pr-151109 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-151109 is completed!
📊 5 regressed and 1 fixed (785666 total)
📊 2258 spurious results on the retry-regressed-list.txt, consider a retry1 if this is a significant amount.
📰 Open the summary report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

Footnotes

  1. re-run the experiment with crates=https://crater-reports.s3.amazonaws.com/pr-151109/retry-regressed-list.txt

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Feb 1, 2026
@tgross35
Copy link
Contributor

tgross35 commented Feb 2, 2026

@craterbot
Copy link
Collaborator

👌 Experiment pr-151109-1 created and queued.
🤖 Automatically detected try build a3a8742
⚠️ Try build based on commit bb1183b, but latest commit is 3387a58. Did you forget to make a new try build?
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 2, 2026
@craterbot
Copy link
Collaborator

🚧 Experiment pr-151109-1 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-151109-1 is completed!
📊 0 regressed and 0 fixed (2080 total)
📊 142 spurious results on the retry-regressed-list.txt, consider a retry1 if this is a significant amount.
📰 Open the summary report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

Footnotes

  1. re-run the experiment with crates=https://crater-reports.s3.amazonaws.com/pr-151109-1/retry-regressed-list.txt

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Feb 3, 2026
@tgross35
Copy link
Contributor

tgross35 commented Feb 3, 2026

For context, the warning looks like this:

warning: an associated constant with this name may be added to the standard library in the future
   --> libm/src/math/support/float_traits.rs:248:48
    |
248 |               const SIGN_MASK: Self::Int = 1 << (Self::BITS - 1);
    |                                                  ^^^^^^^^^^
...
335 | / float_impl!(
336 | |     f64,
337 | |     u64,
338 | |     i64,
...   |
344 | |     fmaf64
345 | | );
    | |_- in this macro invocation
    |
    = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
    = note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
    = note: `#[warn(unstable_name_collisions)]` (part of `#[warn(future_incompatible)]`) on by default
    = note: this warning originates in the macro `float_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
help: use the fully qualified path to the associated const
    |
248 -             const SIGN_MASK: Self::Int = 1 << (Self::BITS - 1);
248 +             const SIGN_MASK: Self::Int = 1 << (<f64 as Float>::BITS - 1);
    |
help: add `#![feature(float_bits_const)]` to the crate attributes to enable `core::f64::<impl f64>::BITS`
   --> libm/src/lib.rs:26:1
    |
 26 + #![feature(float_bits_const)]
    |

I guess crater might not actually show warnings?

In any case, there isn't a problem adding them but we may need to revisit at stabilization.

@bors r+

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 3, 2026

📌 Commit 3387a58 has been approved by tgross35

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 3, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Feb 3, 2026
fN::BITS constants for feature float_bits_const

Also enables the feature for compiler_builtins as otherwise this causes a warning and conflicts with the Float extension trait.

---
Implementation for rust-lang#151073

Feature flag: `#![feature(float_bits_const)]`

Note that this is likely to conflict with some extension traits, as it has with compiler builtins. However, assuming correct values for the constants, they are either `u32`, the same type, which should not cause a problem (as shown by enabling the feature for compiler_builtins), or a different type (e.g. `usize`), which should cause a compiler error. Either way this should never change behaviour unless the extension trait implemented an incorrect value.

Also note that it doesn't seem to be possible to put multiple unstable attributes on an item, so `f128::BITS` and `f16::BITS` are gated behind the feature flags for those primitives, rather than `#![feature(float_bits_const)]`
rust-bors bot pushed a commit that referenced this pull request Feb 3, 2026
Rollup of 6 pull requests

Successful merges:

 - #152008 (`rust-analyzer` subtree update)
 - #151109 (fN::BITS constants for feature float_bits_const)
 - #151976 (Rename `collect_active_jobs` to several distinct names)
 - #151691 (compiletest: Don't assume `aux-crate` becomes a `*.so` with `no-prefer-dynamic`)
 - #151919 (fix: Make `--color always` always print color with `--explain`)
 - #152028 (Convert to inline diagnostics in `rustc_driver_impl`)
rust-bors bot pushed a commit that referenced this pull request Feb 3, 2026
Rollup of 7 pull requests

Successful merges:

 - #152008 (`rust-analyzer` subtree update)
 - #151109 (fN::BITS constants for feature float_bits_const)
 - #151976 (Rename `collect_active_jobs` to several distinct names)
 - #151691 (compiletest: Don't assume `aux-crate` becomes a `*.so` with `no-prefer-dynamic`)
 - #151919 (fix: Make `--color always` always print color with `--explain`)
 - #152017 (Remove `with_no_trimmed_paths` use in query macro)
 - #152028 (Convert to inline diagnostics in `rustc_driver_impl`)
@rust-bors rust-bors bot merged commit 37ece9c into rust-lang:main Feb 3, 2026
12 of 14 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Feb 3, 2026
rust-timer added a commit that referenced this pull request Feb 3, 2026
Rollup merge of #151109 - tyhdefu:float_bits_const, r=tgross35

fN::BITS constants for feature float_bits_const

Also enables the feature for compiler_builtins as otherwise this causes a warning and conflicts with the Float extension trait.

---
Implementation for #151073

Feature flag: `#![feature(float_bits_const)]`

Note that this is likely to conflict with some extension traits, as it has with compiler builtins. However, assuming correct values for the constants, they are either `u32`, the same type, which should not cause a problem (as shown by enabling the feature for compiler_builtins), or a different type (e.g. `usize`), which should cause a compiler error. Either way this should never change behaviour unless the extension trait implemented an incorrect value.

Also note that it doesn't seem to be possible to put multiple unstable attributes on an item, so `f128::BITS` and `f16::BITS` are gated behind the feature flags for those primitives, rather than `#![feature(float_bits_const)]`
github-actions bot pushed a commit to rust-lang/compiler-builtins that referenced this pull request Feb 3, 2026
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#152008 (`rust-analyzer` subtree update)
 - rust-lang/rust#151109 (fN::BITS constants for feature float_bits_const)
 - rust-lang/rust#151976 (Rename `collect_active_jobs` to several distinct names)
 - rust-lang/rust#151691 (compiletest: Don't assume `aux-crate` becomes a `*.so` with `no-prefer-dynamic`)
 - rust-lang/rust#151919 (fix: Make `--color always` always print color with `--explain`)
 - rust-lang/rust#152017 (Remove `with_no_trimmed_paths` use in query macro)
 - rust-lang/rust#152028 (Convert to inline diagnostics in `rustc_driver_impl`)
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Feb 4, 2026
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#152008 (`rust-analyzer` subtree update)
 - rust-lang/rust#151109 (fN::BITS constants for feature float_bits_const)
 - rust-lang/rust#151976 (Rename `collect_active_jobs` to several distinct names)
 - rust-lang/rust#151691 (compiletest: Don't assume `aux-crate` becomes a `*.so` with `no-prefer-dynamic`)
 - rust-lang/rust#151919 (fix: Make `--color always` always print color with `--explain`)
 - rust-lang/rust#152017 (Remove `with_no_trimmed_paths` use in query macro)
 - rust-lang/rust#152028 (Convert to inline diagnostics in `rustc_driver_impl`)
github-actions bot pushed a commit to rust-lang/rust-analyzer that referenced this pull request Feb 5, 2026
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#152008 (`rust-analyzer` subtree update)
 - rust-lang/rust#151109 (fN::BITS constants for feature float_bits_const)
 - rust-lang/rust#151976 (Rename `collect_active_jobs` to several distinct names)
 - rust-lang/rust#151691 (compiletest: Don't assume `aux-crate` becomes a `*.so` with `no-prefer-dynamic`)
 - rust-lang/rust#151919 (fix: Make `--color always` always print color with `--explain`)
 - rust-lang/rust#152017 (Remove `with_no_trimmed_paths` use in query macro)
 - rust-lang/rust#152028 (Convert to inline diagnostics in `rustc_driver_impl`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants