Skip to content
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

Allow wildcard "_" as const pattern #2243

Closed
nvzqz opened this issue Dec 11, 2017 · 6 comments
Closed

Allow wildcard "_" as const pattern #2243

nvzqz opened this issue Dec 11, 2017 · 6 comments
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.

Comments

@nvzqz
Copy link
Contributor

nvzqz commented Dec 11, 2017

One of the things holding static_assertions from becoming 1.0 is a restriction on where the wildcard identifier is allowed. I'm requesting that consts may be allowed to use _ just like with let bindings.

@Centril Centril added the T-lang Relevant to the language team, which will review and decide on the RFC. label Dec 11, 2017
@ExpHP
Copy link

ExpHP commented Dec 11, 2017

Nit: _ is a pattern, not an identifier. To me it'd seem odd to support only _ and not more general patterns (but general patterns do not seem useful for constants).

I feel this issue would be better simply by having some method--any method--of generating a hygienic name for an item (a const, fn, mod, etc.) inside a macro just like we are capable of doing (or perhaps, rather, forced to do) for local variables.

@SimonSapin
Copy link
Contributor

For static_assertions though you don’t actually want a const item, only the side effects of evaluating its initializer, right?

@nvzqz nvzqz changed the title Allow wildcard "_" as const ident Allow wildcard "_" as const pattern Dec 12, 2017
@nvzqz
Copy link
Contributor Author

nvzqz commented Dec 12, 2017

@SimonSapin yes, I'm mainly after the side effects. This is one way I can think of achieving what I want with minimal effect on the language. This is also a backwards-compatible change.

A const item using _ would allow for using the compile-time side effects multiple times within the same context without naming conflicts.

@eddyb
Copy link
Member

eddyb commented Dec 12, 2017

const destructuring (const (A, B): (&str, i32) = ("foo", 0);) might be a very nice addition, and then the _ patterns would come "for free". cc @nikomatsakis

@nvzqz
Copy link
Contributor Author

nvzqz commented Dec 13, 2017

I actually spoke to Niko about this a month ago. He recommended to add something like my const_assert macro to the language instead. The issue is that I need this issue for other macros within this crate as well.

@eddyb I really like the idea of adding constant destructuring to the language! This should also work for statics.

@Centril
Copy link
Contributor

Centril commented Oct 7, 2018

Closing in favor of #2526.

@Centril Centril closed this as completed Oct 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

5 participants