-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
inline-const is not an expr in macros, but it should be #84155
Comments
Is it possible there's some check for the first keyword of a Sadly I'm not sure where that would be. I think I've seen a few different things like that but most of them for advanced diagnostics or that "FOLLOW sets" check on macro definitions (whereas this is happening during expansion). |
This was introduced in #80135 to fix a regression. |
Reading through that, and, oh no. Can we have a different expr type in macros that supports const or something? It seems like it's not possible to avoid this side of the bug because you can't wrap a pattern in {} or turn it into an expr. |
This makes it possible to use `inline_const` (rust-lang#76001) and `let_chains` (rust-lang#53667) inside macros' `expr` patterns in a future edition by bifurcating the `expr` nonterminal in a similar way to `pat2021` to remove some backwards compatibility exceptions that disallow `const`/`let` at the beginning of an `expr` match. Fixes rust-lang#84155 and relaxes the backward compat restriction from rust-lang#80135 for a future edition. This is not intended to go into 2021 as it I don't think it's simple to write an automatic fix, and certainly not now that it's past the soft deadline for inclusion in 2021 by a long shot. Here is a pathological case of rust-lang#79908 that forces this to be an edition change: ```rust macro_rules! evil { ($e:expr) => { // or something else const {$e-1} }; (const $b:block) => { const {$b} } } fn main() { let x = 5; match x { evil!(const { 5 }) => panic!("oh no"), _ => (), }; } ```
Closing in favor of #86730. |
While writing a macro thingy that generates match blocks, I had a problem where it was previously using an
expr
type, but that didn't work[1], as it didn't accept the inlineconst
as anexpr
, so I tried putting it as apat
instead, but that didn't work[2] aspat
s aren't accepted in exprs, even if they would be valid in text form.[1] The subject of this bug report:
Compile failure (the subject of this bug):
[2] The thing I tried, that I think is probably reasonable behaviour, although the error needs improvement:
Error:
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: