-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking issue for RFC 2526, "Support underscores as constant names" #54912
Comments
Ugh, seems like a legitimized hack rather than a... well, any of several proper features to which this can be generalized. At least this is a very tiny hack. |
Hehe, I agree we should generalize (to patterns) eventually but it seemed that it was much more complex from @eddyb's comments. :) |
looks interesting, I will give it a try! |
Can we also ensure that those gensyms get removed after before codegen? This means, the generated MIR should be removed in some MIR rounds. |
We don't need to remove any |
Fine. There is one "inconsistency" in Rust today: let _: str = *"123"; //Legal
let _v: str = *"123"; //Illegal unless unsized_rvalues When implementing this, how do we want to justify const _: str = *"123";
const _v: str = *"123"; Shall we repeat the inconsistency, or shall we count both valid or invalid? |
I'd start out with both being disallowed, since that is the current behaviour of constants. But I have no strong opinion. |
…enkov Support underscore as constant name Issue: #54912
Setting earliest date for stabilization proposal to 25th november 2018 (14 days from now). We'll likely want to discuss what direction generalizations should go in before stabilizing. |
The RFC did not discuss Fix for the stability hole is in #55983 |
I'm having a bit of second thoughts about this RFC. I feel like (a) the intention of The motivation of "ensure some code type-checks" is real though. I sort of like the syntax I guess I'm probably just re-raising thoughts that came up on the RFC. |
Could that be re-used for explicit promotion as @oli-obk plans it? |
@RalfJung seems plausible. The one concern I could see is whether there would be some conflict as |
Wouldn't that defeat the purpose of explicit promotion? |
With respect to a) the intention of My main worry is instead b) and c). That is, would we permit this? const (A, B): (AType, BType) = (1, 2); (this would be the natural extension of but also this? const A<T>: AType<T> = expr; and how can these be composed? If we write: const (A<T>, B<U>): (AType<U>, BType<T>) = expr; does that make any sense? I suppose that we could support generic constants when Finally, ideally, to keep the language consistent, we should keep As for supporting
|
|
I believe it is pretty clear to user as we can use |
I don't think that's a useful interpretation. There's absolutely nothing this I agree with everything else. We should just allow constants with patterns and generic constants. We already support them inconveniently by defining a const function without arguments. |
It's not. Notably, you may only reference existing bindings. Any function calls must still be
There's plenty this would tell you:
Now.. it might be confusing to have block form entitled |
I don't really understand how generic constants can cause issues with unnamed consts, and AFAIK supporting |
Currently, the constants show up as _ in the documentation. https://sunriseos.github.io/SunriseOS/master/sunrise_ahci/hba/index.html#constants |
I think we should stabilize this as soon as its implemented; I'd expect statics and consts to both be irrefutable pattern positions. I don't think its important to keep statics and consts the same; I think its already inconsistent that they don't take irrefutable patterns, and bringing one of them closer to that now is better than waiting until they are both at feature parity and moving them together. In particular, unnamed statics have real semantic questions as to whether the place gets created or not. |
If the |
That's not "just like |
It is unfortunate that Rust was designed that way and we do not have a way back. It is really confusing to even experienced users unless they jump into the very deep level of the language. If this feature could ever be designed again, I would hope that
|
Did you mean that it does drop the guard? |
Dang, it got me again... this does not drop though: fn main() {
let mutex = Mutex::new(());
let val = mutex.lock().unwrap();
let _ = val; // does not drop nor move.
let _ = mutex.lock().unwrap();
} |
I think the confusion here is the direction of the conversion. Matching against a pattern always does a "value to place" conversion, as patterns require places to do discriminant checks and field accesses, so:
So depending on some exact details around unsafe code and whatnot, |
I think it would be good to fix this so that we treat |
You don't need |
@petrochenkov Are there any observable differences between |
No, there should be no observable difference after #56392. |
We discussed this on the language team meeting today and gave the green light for a stabilization report and PR (see above). I will be writing the report and adding it to the PR within a few hours. |
1847: Allow an underscore as the identifier in `const` items r=matklad a=ecstatic-morse [RFC 2526](rust-lang/rust#54912) was recently stabilized, meaning `const _: i32 = 5;` is now a valid item. Co-authored-by: Dylan MacKenzie <ecstaticmorse@gmail.com>
Omit underscore constants from rustdoc Underscore constants from rust-lang/rfcs#2526 / rust-lang#54912 do not correspond to a nameable item and so are never useful in documentation. <br> #### Before: > <img src="https://user-images.githubusercontent.com/1940490/71771409-0427cc80-2eef-11ea-8b7d-d9c74a873e7e.png" width="60%"> #### After: > Not that.
Omit underscore constants from rustdoc Underscore constants from rust-lang/rfcs#2526 / rust-lang#54912 do not correspond to a nameable item and so are never useful in documentation. <br> #### Before: > <img src="https://user-images.githubusercontent.com/1940490/71771409-0427cc80-2eef-11ea-8b7d-d9c74a873e7e.png" width="60%"> #### After: > Not that.
This is a tracking issue for the RFC "Support underscores as constant names" (rust-lang/rfcs#2526).
Steps:
Implementstatic _
as wellunderscore_const_names
reference#620Unresolved questions:
None
The text was updated successfully, but these errors were encountered: