Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Stabilize const for integer {to,from}_{be,le,ne}_bytes methods #69373
Stabilize const for integer {to,from}_{be,le,ne}_bytes methods #69373
Changes from all commits
d15a98b
87f0dc6
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use the union based implementation as done in the aforementioned PR instead of the transmute based one with the macro, as that seems more hacky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Centril This code doesn't compile. Transmute or not you'll either need that hack macro or fix
#[allow_internal_unstable]
.(Also, a union doesn't check the type size. Using a union is equivalent to doing transmute_copy which is more dangerous than transmute)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The macro doesn't do the same thing as
#[allow_internal_unstable]
on aconst fn
, at all.The
const fn
is a different feature that's reusing the attribute and given how confused I was by it, it should be using a different attribute.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whether "fixing
#[allow_internal_unstable]
" or "create another attribute forconst fn
" requires changing the compiler and blocks this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, changing the attribute's name to not be confusing won't make it work for non-language features anyway.
My point was that there's no reason to use a macro, because it's the same as adding the feature at the crate level, just unnecessarily complicated.
It doesn't have the special semantics @oli-obk added to the attribute when applied to
const fn
, it's just a free pass.Overall I am pretty confused at how this system is supposed to work and I don't think I want to merge this PR until we hear from @oli-obk.
Also, we don't need to wait for a change to the attribute to trickle into beta because we can always
#![cfg_attr(bootstrap, feature(const_transmute))]
or w/e.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const fn
situation which is only relevant for "stablyconst fn
")If anything this probably shows we might want
#![feature(...)]
on arbitrary scopes, not just crate-level, and then you can lint againstconst_*
features being applied at a scope larger than an individualconst fn
, if you want to.const fn
definitions then wouldn't need a separate attribute, since the tight feature-gate scoping would just be a general feature at that point that they can just use instead of something special for them.While
macro_rules!
macros would continue to require an attribute, although it might make sense to have#[feature(foo)] #[rustc_inherit_unstable]
instead of#[allow_internal_unstable(foo)]
.Anyway this is all just speculation, if nothing else, I want to use a different name that's clearly about
const
(fn
) to make it searchable and more of a warning sign.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine just naming it
#[rustc_allow_const_feature(foo)]
, but the reason I reused the existing attribute was because it seems like the same thing to me. There's some thing callable by users (stably or unstably) that uses an unstable feature inside and we don't want the user to have to specify the feature. It's slightly better isolated in the const fn case than in the macro case, but it's still essentially the same logic to me.Anyway, as said at the start of this post, I'm fine renaming it. Especially since people are confused by const fn having the same attribute as macro_rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I converted from transmute to union as suggested by @Centril, and that incidentally allowed this to build as unions are language features not library features.
However, now I'm reading the point by @kennytm that a union doesn't check the type size, so if that causes an issue I can revert that bit. (I don't think it's an issue here, the union is between
$SelfT
and[u8; mem::size_of::<$SelfT>]
.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea the change looks alright. We'll want to move back to transmute at some point, so I added the const-hack label to this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fwiw, this was not incidental at all; that's why I suggested it. ;)