Visitar URL original
Use a macro to reduce duplication in `core/src/num/f{16,32,64,128}.rs` (part 2) by beetrees · Pull Request #165773 · rust-lang/rust · GitHub
Skip to content

Use a macro to reduce duplication in core/src/num/f{16,32,64,128}.rs (part 2) - #165773

Open
beetrees wants to merge 2 commits into
rust-lang:mainfrom
beetrees:float-macro-2
Open

beetrees wants to merge 2 commits into
rust-lang:mainfrom
beetrees:float-macro-2

Conversation

@beetrees

@beetrees beetrees commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

This is the sequel to #163410, moving the float classification methods to the macro. To make this easier to review, in the first commit I've included a copy-paste of the new parts of the macro in the same place as where the methods have been moved from, so the diff will show the changes. I've then removed these duplicates in the second commit, leaving the final state with no duplication.

r? @ChrisDenton

@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 Nov 10, 2026
@beetrees beetrees changed the title Use a macro to reduce duplication in core/src/num/f{16,32,64,128}.rs (part 2) Use a macro to reduce duplication in core/src/num/f{16,32,64,128}.rs (part 2) Nov 10, 2026
@rust-log-analyzer

This comment has been minimized.

@beetrees
beetrees marked this pull request as draft November 10, 2026 18:26
@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 Nov 10, 2026
@beetrees
beetrees marked this pull request as ready for review November 10, 2026 18:36
@rustbot

rustbot commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 10, 2026
Comment thread library/core/src/intrinsics/mod.rs Outdated
/// The stabilized version of this intrinsic is [`f16::min`].
#[rustc_nounwind]
#[rustc_intrinsic]
#[rustc_const_unstable(feature = "f16", issue = "116909")]

@RalfJung RalfJung Nov 11, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why are you adding this? Stability attributes on intrinsics are unusual as intrinsics are not meant to be stabilized.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Now removed, see below.

Comment thread library/core/src/num/f128.rs Outdated
#[inline]
#[doc(alias = "nextUp")]
#[unstable(feature = "f128", issue = "116909")]
#[rustc_const_unstable(feature = "f128", issue = "116909")]

@RalfJung RalfJung Nov 11, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

FWIW this makes the function unstable to use inside std from stable code. It should only be used if the body of the function needs const-unstable features. Why did you add this?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Of the unstable functions I moved to the macro, currently one has rustc_const_unstable (is_finite), and some don't. I thought it would be more consistent for them all to have the attribute; I hadn't seen the rustc-dev-guide section that says it's "only needed in rare cases" "If a const fn makes use of unstable language features or intrinsics". As you say, rustc_const_unstable makes a function require the rustc_const_unstable attribute to use it within std: next_up calls is_nan, so adding the rustc_const_unstable to is_nan means that it also must be added to next_up.

I've removed the rustc_const_unstable attributes this PR added, so this is no longer an issue.

This branch has not been deployed

No deployments
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.

5 participants