Skip to content

Conversation

lukas-code
Copy link
Member

Previously this code failed to compile on edition 2021. (Playground)

fn main() {
    matches!((), ());
}
   Compiling playground v0.0.1 (/playground)
error: `$pattern:pat` may be followed by `|`, which is not allowed for `pat` fragments
    |
    = note: allowed there are: `=>`, `,`, `=`, `if` or `in`

error: aborting due to previous error

error: could not compile `playground`

To learn more, run the command again with --verbose.

@rust-highfive
Copy link
Contributor

r? @dtolnay

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 25, 2021
Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Is it possible to get a test for this? I believe the ui test harness supports setting the edition that tests are built with.

// edition:2021
// compile-flags: -Zunstable-options

@lukas-code
Copy link
Member Author

I added a regression test.

@ehuss
Copy link
Contributor

ehuss commented May 25, 2021

I haven't seen any discussion about proceeding with this solution for #84429. As of this morning, there is work going on to fix the hygiene problem. Was there some discussion on this?

@petrochenkov
Copy link
Contributor

@ehuss

I haven't seen any discussion about proceeding with this solution for #84429.

#84452 (comment) ?

@ehuss
Copy link
Contributor

ehuss commented May 25, 2021

Ah, forgot about that! I do believe they should be equivalent, even when std is migrated to 2021, so I don't think it matters much one way or the other.

Just a forewarning, I think this may conflict with #85272, so the two PRs will be racing one another.

@dtolnay
Copy link
Member

dtolnay commented May 26, 2021

@bors r+

@bors
Copy link
Collaborator

bors commented May 26, 2021

📌 Commit 824c743 has been approved by dtolnay

@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 May 26, 2021
@Aaron1011
Copy link
Contributor

Note that this PR only fixes the problem for the specific matches! macro in the standard library. Any 2018 edition crate which defines a similar macro will have the same problem when invoked from a 2021-edition crate. This PR is still fine to land, since we're just explicitly indicating (via :pat_param) the behavior that we should be getting from :pat.

PR #85709 fixes this for all macro definitions.

bors added a commit to rust-lang-ci/rust that referenced this pull request May 26, 2021
Rollup of 8 pull requests

Successful merges:

 - rust-lang#85478 (Disallow shadowing const parameters)
 - rust-lang#85625 (Prevent double drop in `Vec::dedup_by` if a destructor panics)
 - rust-lang#85627 (Fix a few details in THIR unsafeck)
 - rust-lang#85633 (Post-monomorphization errors traces MVP)
 - rust-lang#85670 (Remove arrays/IntoIterator message from Iterator trait.)
 - rust-lang#85678 (fix `matches!` and `assert_matches!` on edition 2021)
 - rust-lang#85679 (Remove num_as_ne_bytes feature)
 - rust-lang#85712 (Fix typo in core::array::IntoIter comment)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3c2a709 into rust-lang:master May 26, 2021
@rustbot rustbot added this to the 1.54.0 milestone May 26, 2021
@lukas-code lukas-code deleted the matches2021 branch May 26, 2021 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants