-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Turn constants in modules core::[i/u][8/16/32/64/size] into associated constants #28656
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
// FIXME(#11621): Should be deprecated once CTFE is implemented in favour of | ||
// calling the `mem::size_of` function. | ||
#[unstable(feature = "num_bits_bytes", | ||
reason = "may want to be an associated function", |
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.
reason needs update
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.
Why? It still may want to be an associated function, just like std::usize::BYTES
.
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 believe this reason was written down long before we even had associated constants, but with those I don't think we'd want both a constant and a function, and in today's Rust these are definitely most appropriate as a constant.
Issue #28586 means this may cause ICEs (const is ok in array sizes but associated consts are not). |
Needs |
That issue is interesting, because there is no associated constant |
Maybe the regular |
9be4f63
to
7792636
Compare
Yes, that would be reasonable. Updated. |
☔ The latest upstream changes (presumably #28610) made this pull request unmergeable. Please resolve the merge conflicts. |
7792636
to
e486076
Compare
Rebased. |
let &(ref fqp, short) = cache.paths.get(&did).unwrap(); | ||
if i > 0 { | ||
try!(write!(&mut w, ",")); | ||
if let Some(&(ref fqp, short)) = cache.paths.get(&did) { |
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.
How come this was necessary? It seems like this may indicate a bug in rustdoc rather than something that should be ignored?
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.
Yes, it's certainly a rustdoc bug, I spent may be a couple of hours trying to fix it, but haven't found out what's wrong.
I'm also a little wary of deprecating an unstable feature in favor of something which may not work in all situations (e.g. those who migrate may end up hitting ICEs). I think it'd be fine to introduce these as associated constants, however in addition to leaving the previous |
Given that #28586 is a hard issue and is unlikely to be resolved soon, I'm ok with undeprecating. |
e486076
to
ad7a32a
Compare
Updated. |
Thanks! Just a few more questions:
@bluss could you elaborate on what the breaking change is? Was it the deprecation? On the surface this looks like a backwards-compatible change to me, but I haven't worked too closely with associated constants yet! |
Don't think there is any breaking change anymore. It was the removal of the old unstable |
That said I don't know how code will respond to |
It is resolved to
If I could do it in reasonable time, I'd fix it, but I can't (as I said, I've already spent too much time on it). I can fill an issue and someone (maybe future me) will fix it later.
I need to investigate. |
Associated constants can be used on stable, but not defined. |
Hm ok, in that case I'd be more comfortable if these stayed as unstable for now to ensure we don't let usage accidentally leak in (I don't think we have many other stable associated constants). Given that, though, can you remind me what the motivation for this change is? We'd definitely want to make the switch once associated constants are stable, but while they're in limbo we may want to be cautious about exposing and using them. You mention we can make some changes to resolve, but can you elaborate on that as well? |
Primitive types are currently special-cased in resolve. In particular, this special casing implies weird shadowing rules. They are so weird they have to be guarded by a hack (#22093). This is all bad (rust-lang/rfcs#907 (comment)). Ideally, primitive types should live in the prelude and be resolved as all other types. If the new primitive types are added ( Sooo... The only remaining motivation for this change is ability to use |
Hm ok, I must admit that I'm not very familiar with the resolve parts of this, but from what it sounds like the benefits of this may be pretty small by this point? If major overhauls are required before associated constants are usable like constants today it may be best to wait on this change? |
Ok, it's not urgent. |
Can this be revived now? |
Yes, I think. Associated constants are in much better state now and we have crater to check for breakage. |
Module versions of the constants are left in place for both stability reasons and as an escape hatch for #28586
After this change (and after the resolution of #28586) primitive types
[i/u][8/16/32/64/size]
andbool
can be put into the prelude and not treated specially in resolve (the same can't be done backward-compatibly withf[32/64]
,char
andstr
, unfortunately).