-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Support underscores as constant names #2526
Conversation
Alternatives section looks barren. I know some ink has been spilt in the past on the alternative of unnamed modules ( IIRC, one of the primary arguments against that was that hygienic |
Good call; I'll add that. Do you know where said ink was spilled so I can link to it?
How would that work? |
@joshlf |
Declarative macros are unstable and way bigger than this proposal. That also forces you to use a macro when you could just be doing some compile-time assertions by hand or through a I'm in favour of this proposal. |
How about supporting all irrefutable patterns in a similar way to const (foo, bar): (T, U) = computeFooAndBar(); |
74e8d80
to
be40ba7
Compare
This seems reasonable to me. |
Another alternative is to support unnamed fn like |
be40ba7
to
6e5ef11
Compare
Added to the Alternatives section. |
@rfcbot merge We discussed the RFC on this week's language team meeting. The general consensus was that we should do this. The proposal seems small in scope, is readily implementable, and it would be useful in some cases (e.g. those mentioned in the motivation, particularly wrt. custom derive macros). It also seems to me that the meaning would be understandable given that I would personally like us to go further in the future to generally allow irrefutable patterns so that you can write |
Team member @Centril has proposed to merge this. The next step is review by the rest of the tagged teams:
No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
Is there a reason to only allow this for |
@Havvy How would it work for I think |
No, it wouldn't make sense for any item other than But looking at |
@Havvy Right, in the case of |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
If the only purpose of this is to create an anonymous top-level scope, it kind of seems like a hack.[1] Especially since you have to give the underscore a "type" of If the goal is to have a facility for scopes at the top level, perhaps we should... just allow curly-braced scopes at top level? [1] If consts could be declared with patterns, this could also be useful in the following code: const fn foo() -> (i32, i32) { /* ... */ }
const (X, _): (i32, i32) = foo(); But that doesn't work today even with identifiers. |
text/0000-const-wildcard.md
Outdated
|
||
Allow assigning to `_` when defining a new constant. Just like `let _`, this | ||
doesn't introduce any new bindings, but still evaluates the rvalue at compile | ||
time like any other constant. |
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.
A guide-level explanation does not include the word "rvalue", IMO. And this doesn't explain what the point of the feature is.
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.
Is there a phrase you'd suggest instead of "rvalue"?
The point of the feature is described in the "Motivation" section.
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.
What C
and C++
call an rvalue
, we call a value expression
. See the reference on this.
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 think we've called it rvalue
for some time as well.. see https://github.com/rust-lang/rfcs/blob/master/text/1414-rvalue_static_promotion.md.
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.
We used to call it rvalue, but we've wisened up since then. Likewise with lvalues (now places).
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.
@rkruppe you speak the truth :)
@durka As you suggest, the idea is that this is the first step on the way towards fully-general patterns like |
The final comment period, with a disposition to merge, as per the review above, is now complete. |
Huzzah! This RFC has been merged! Tracking issue: rust-lang/rust#54912 |
The |
@matthiaskrgr you know it takes a few seconds to change the URL and everything; I'm not a bot =P |
Ooh, sorry! 😆 |
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.
Allow the syntax
const _: TYPE = VALUE
, analogous tolet _ = VALUE
.Rendered
Tracking issue
Discussion on internals here.