-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add a note to the ArbitraryExpressionInPattern error #124488
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
Conversation
7974b09
to
d339d1a
Compare
This comment has been minimized.
This comment has been minimized.
d339d1a
to
4284bca
Compare
Note that should in the future anyone discover cases where there was no involvement of |
#99380 is interesting. It seems like the intent was to signal that the macro definition itself is ill-formed, but the error reporting machinery is only firing after the macro itself is invoked, and only highlights the macro invocation site, rather than saying anything at all about the macro definition. Does that sound like a reasonable synopsis of what problem the error message itself was trying to address, @est31 ? |
@bors r+ rollup |
…iaskrgr Rollup of 3 pull requests Successful merges: - rust-lang#124185 (Remove optionality from MoveData::base_local) - rust-lang#124488 (Add a note to the ArbitraryExpressionInPattern error) - rust-lang#124530 (Fix Fuchsia build broken by rust-lang#124210) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#124488 - est31:arbitrary_expressions_error, r=pnkfelix Add a note to the ArbitraryExpressionInPattern error The current "arbitrary expressions aren't allowed in patterns" error is confusing, as it fires for code where it *looks* like a pattern but the compiler still treats it as an expression. That this is due to the `:expr` fragment specifier forcing the expression-ness property on the code. In the test suite, the "arbitrary expressions aren't allowed in patterns" error can only be found in combination with macro_rules macros that force expression-ness of their content, namely via `:expr` metavariables. I also can't come up with cases where there would be an expression instead of a pattern, so I think it's always coming from an `:expr`. In order to make the error less confusing, this adds a note explaining the weird `:expr` fragment behaviour. Fixes rust-lang#99380
I don't know what the original intent of the error was but in many cases, the usual way to resolve is indeed to change the fragment specifier from Before this patch, the error message was extremely terse and would cause a lot of confusion as to why it's an expression and not a pattern. Now, it at least mentions fragment specifiers. I could have made it point to the fragment specifier but the only way I could find would involve changing both the token and AST format to include the additional data: not sure it's worth that. I have it in this branch.
|
The current "arbitrary expressions aren't allowed in patterns" error is confusing, as it fires for code where it looks like a pattern but the compiler still treats it as an expression. That this is due to the
:expr
fragment specifier forcing the expression-ness property on the code.In the test suite, the "arbitrary expressions aren't allowed in patterns" error can only be found in combination with macro_rules macros that force expression-ness of their content, namely via
:expr
metavariables. I also can't come up with cases where there would be an expression instead of a pattern, so I think it's always coming from an:expr
.In order to make the error less confusing, this adds a note explaining the weird
:expr
fragment behaviour.Fixes #99380