-
Notifications
You must be signed in to change notification settings - Fork 13.3k
regression 1.49: macro_rules unexpected tokens #79908
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
The |
https://crates.io/crates/fourier only lists 0.1.0 so we should probably nag @calebzulawski about a point release one more time :) |
Whoops, looks like I half-fixed it. One of my dependencies is too strict. It does look like the same error so probably not a regression... |
@apiraino and I both feel unclear about this: Is this a Rust regression or a regression in a library that was then picked up by Crater? |
This is a regression in the Rust compiler. |
The Reposting the error here:
|
But I'm not quite sure; the span seems potentially wrong. |
@rustbot ping cleanup would be nice to get an MCVE |
Hey Cleanup Crew ICE-breakers! This bug has been identified as a good cc @AminArria @camelid @chrissimpkins @contrun @DutchGhost @elshize @ethanboxx @h-michael @HallerPatrick @hdhoang @hellow554 @imtsuki @JamesPatrickGill @kanru @KarlK90 @LeSeulArtichaut @MAdrianMattocks @matheus-consoli @mental32 @nmccarty @Noah-Kennedy @pard68 @PeytonT @pierreN @Redblueflame @RobbieClarken @RobertoSnap @robjtede @SarthakSingh31 @shekohex @sinato @smmalis37 @steffahn @Stupremee @tamuhey @turboladen @woshilapin @yerke |
Somewhat minimized (playground): macro_rules! exp {
(const $n:expr) => {
Box::new(Exp::Const($n))
};
}
macro_rules! stmt {
(exp $e:expr) => {
Box::new(Stmt::Exp($e))
};
(exp $($t:tt)+) => {
Box::new(Stmt::Exp(exp!($($t)+)))
};
}
macro_rules! seq {
($stmt1:expr; $stmt2:expr $(;)?) => {
Box::new(Stmt::Seq($stmt1, $stmt2))
};
($stmt1:expr; $stmt2:expr; $($stmt:expr);+ $(;)?) => {
seq!(seq!($stmt1; $stmt2); $($stmt);+)
};
}
fn main() {
let seq = seq!(
stmt!(exp const 1);
stmt!(exp const 2);
stmt!(exp const 3);
);
} On stable, it produces a bunch of semantic errors (which make sense since I removed a lot of type definitions), but on beta it produces:
|
Assigning |
Much more minimized: macro_rules! exp {
(const $n:expr) => {
$n
};
}
macro_rules! stmt {
(exp $e:expr) => {
$e
};
(exp $($t:tt)+) => {
exp!($($t)+)
};
}
fn main() {
stmt!(exp const 1);
} Errors:
|
Here's the code again: macro_rules! exp {
(const $n:expr) => {
$n
};
}
macro_rules! stmt {
(exp $e:expr) => {
$e
};
(exp $($t:tt)+) => {
exp!($($t)+)
};
}
fn main() {
stmt!(exp const 1);
} I think the issue is that on beta the compiler thinks the On stable this is not an issue because the compiler never thinks that I think the fix might be to not treat See the original cc @spastorino who has been implementing |
My bisection is in line with my diagnosis: searched nightlies: from nightly-2020-10-15 to nightly-2020-10-19 bisected with cargo-bisect-rustc v0.6.0Host triple: x86_64-apple-darwin cargo bisect-rustc --preserve --regress=error --start=2020-10-15 --end=2020-10-19 |
I'm going to try working on this. If I get stuck I'll release my assignment since this is P-high! |
So I'm trying to figure out which code is the culprit here. The Since this issue is P-critical and potentially a release blocker, I'm going to release my assignment so that someone more experienced can take it over. Though I'm happy to help if there's some way to do that! |
Actually, I just noticed that petrochenkov responded to my message asking for help finding the code 😄 |
Don't allow `const` to begin a nonterminal Fixes rust-lang#79908. Thanks to Vadim Petrochenkov who [told me what the fix was][z]! [z]: https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/finding.20which.20macro.20rule.20to.20use/near/220240422 r? `@petrochenkov`
This should be fixed on the next nightly. |
Reopening to track beta fix. |
Should be backported to beta as part of #80417. |
I think this can be closed as #80417 has been merged? |
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"), _ => (), }; } ```
Unclear on the extent to which these are the same problem:
cc @petrochenkov @Aaron1011
The text was updated successfully, but these errors were encountered: