Add const support for float rounding methods by ruancomelli · Pull Request #141521 · rust-lang/rust (original) (raw)

Hey @RalfJung and @CAD97, I've addressed or replied to all of your review comments.

I've also created a tracking issue for this feature here: #141555.

I have two main open questions now.

First one is: should the rounding methods on f16 and f128 be gated behind #[rustc_const_unstable(feature = {"f16", "f128"}, issue = "116909")] (from #116909) or #[rustc_const_unstable(feature = "const_float_round_methods", issue = "141555")]? I think it should be the former one, but I'm not sure.

The second question: I added #![feature(const_float_round_methods)] to library/std/src/lib.rs, which was suggested by the compiler itself. Without it, ./x check results in the following errors:

error: `core::f32::math::floor` is not yet stable as a const fn
  --> library/std/src/f32.rs:50:9
   |
50 |         core::f32::math::floor(self)
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: add `#![feature(const_float_round_methods)]` to the crate attributes to enable
  --> library/std/src/lib.rs:433:1
   |
433+ #![feature(const_float_round_methods)]
   |

... and similar for the other rounding methods

error: could not compile `std` (lib) due to 12 previous errors

This is similar to what was done in the reference PR, even though they changed library/core/src/lib.rs (notice core and not std).
However, I'm not sure if this is the correct way to proceed. I read the dev guide book, but that question remained unanswered.