-
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
Allow _ @ CONST
in match arms
#2941
Comments
with #2920 you could also write match x {
const { CONST } => { },
_ => { },
} furthermore, because of rust-lang/rust#65490, it is not an error that the |
The problem with Using match x {
CONST1 => { },
CONST2 => { },
} The compiler will warn you if you forgot to import |
if we follow the roadmap in #263 (comment) treating |
I raised the There are two interesting replies that suggest the extra noise from requiring the keyword in the pattern would be too annoying for the value. We're very good at emitting at least one warning in the mistaken cases here; is there maybe a subset that we could upgrade to be deny-by-default because it's so unlikely to be correct? |
The following is currently not valid:
Apparently because the grammar requires an identifier on the lhs of
@
. Replacing_
by_x
makes the code compile.Writing
is ambiguous without a complete analysis of the surrounding module.
CONST
might be a variable name or a constant. The difference impacts which arm is taken.On the other hand,
is unambiguous but introduces the useless variable
_x
.Therefore my proposal is as follows:
valid syntax.
where
CONST
could either be a constant or a variable name in the next edition.The text was updated successfully, but these errors were encountered: