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

Don't allow const to begin a nonterminal #80135

Merged
merged 1 commit into from
Dec 18, 2020
Merged

Conversation

camelid
Copy link
Member

@camelid camelid commented Dec 17, 2020

Fixes #79908.

Thanks to Vadim Petrochenkov who told me what the fix was!

r? @petrochenkov

@camelid camelid added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-parser Area: The parsing of Rust source code to an AST. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 17, 2020
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 17, 2020
@camelid
Copy link
Member Author

camelid commented Dec 17, 2020

Beta-nominating because this fixes a P-critical regression from stable to beta.

@camelid camelid added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Dec 17, 2020
@petrochenkov
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Dec 17, 2020

📌 Commit d6f1787 has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 17, 2020
@camelid
Copy link
Member Author

camelid commented Dec 17, 2020

Should this be p=1 because it fixes a P-critical regression?

@camelid
Copy link
Member Author

camelid commented Dec 17, 2020

Likewise, I don't think this should be rollup because we want to be able to easily bisect in case this causes any issues.

RalfJung added a commit to RalfJung/rust that referenced this pull request Dec 18, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 18, 2020
Rollup of 6 pull requests

Successful merges:

 - rust-lang#80121 (Change the message for `if_let_guard` feature gate)
 - rust-lang#80130 (docs: Edit rustc_span::symbol::Symbol method)
 - rust-lang#80135 (Don't allow `const` to begin a nonterminal)
 - rust-lang#80145 (Fix typo in rustc_typeck docs)
 - rust-lang#80146 (Edit formatting in Rust Prelude docs)
 - rust-lang#80147 (Add missing punctuation to std::alloc docs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 9269995 into rust-lang:master Dec 18, 2020
@rustbot rustbot added this to the 1.50.0 milestone Dec 18, 2020
@camelid camelid deleted the const-macro-nt branch December 18, 2020 19:42
@petrochenkov
Copy link
Contributor

Ok, looks like the questions above already resolved themselves without my involvement.

@camelid
Copy link
Member Author

camelid commented Dec 19, 2020

Oh well :)

@Mark-Simulacrum Mark-Simulacrum added the beta-accepted Accepted for backporting to the compiler in the beta channel. label Dec 25, 2020
@Mark-Simulacrum Mark-Simulacrum removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Dec 27, 2020
@Mark-Simulacrum Mark-Simulacrum modified the milestones: 1.50.0, 1.49.0 Dec 27, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 28, 2020
…ulacrum

[beta] backports

This backports the following to 1.49:

*  Revert change to trait evaluation order rust-lang#80132
*  Don't allow `const` to begin a nonterminal rust-lang#80135
*  Prevent caching normalization results with a cycle rust-lang#80246

r? `@Mark-Simulacrum`
@lf- lf- mentioned this pull request Apr 20, 2021
lf- added a commit to lf-/rust that referenced this pull request Apr 26, 2021
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"),
        _ => (),
    };
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-parser Area: The parsing of Rust source code to an AST. beta-accepted Accepted for backporting to the compiler in the beta channel. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

regression 1.49: macro_rules unexpected tokens
6 participants