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

never patterns: Document behavior of never patterns with macros-by-example #119622

Merged
merged 1 commit into from
Jan 5, 2024

Conversation

Nadrieril
Copy link
Member

never_patterns makes ! parse as a pattern so I was worried about breaking macros-by-example matching. Turns out we're fine because the cases that now match $p:pat used to error in the past. The only tricky case is ! by itself, which backwards-compatibly doesn't match $p:pat. I have no idea why tho, I didn't think of that when I was implementing parsing 😅.

This adds tests so we don't regress the current behavior.

r? @compiler-errors

@Nadrieril Nadrieril added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) F-never_patterns `#![feature(never_patterns)]` labels Jan 5, 2024
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 5, 2024
}

macro_rules! detect_pat {
($p:pat) => {
Copy link
Member

Choose a reason for hiding this comment

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

Wait, weren't the pat macro metavar matchers adjusted for editions >= 2021? Please make an //edition:2021 version of this test.

Copy link
Member Author

@Nadrieril Nadrieril Jan 5, 2024

Choose a reason for hiding this comment

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

Oh shoot well spotted that does have a different behavior. Still backwards-compatible, but a bit inconsistent :/

Copy link
Member Author

@Nadrieril Nadrieril Jan 5, 2024

Choose a reason for hiding this comment

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

Yup, I checked on the playground, this is backwards-compatible. And in fact the assymetry of ! | true vs true | ! in edition 2021 can't be changed

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

r=me after nit

@Nadrieril Nadrieril force-pushed the never_patterns_macros branch from d9e47be to 718a433 Compare January 5, 2024 18:24
@Nadrieril
Copy link
Member Author

@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented Jan 5, 2024

📌 Commit 718a433 has been approved by compiler-errors

It is now in the queue for this repository.

@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 Jan 5, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 5, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#119151 (Hide foreign `#[doc(hidden)]` paths in import suggestions)
 - rust-lang#119350 (Imply outlives-bounds on lazy type aliases)
 - rust-lang#119354 (Make `negative_bounds` internal & fix some of its issues)
 - rust-lang#119506 (Use `resolutions(()).effective_visiblities` to avoid cycle errors in `report_object_error`)
 - rust-lang#119554 (Fix scoping for let chains in match guards)
 - rust-lang#119563 (Check yield terminator's resume type in borrowck)
 - rust-lang#119589 (cstore: Remove unnecessary locking from `CrateMetadata`)
 - rust-lang#119622 (never patterns: Document behavior of never patterns with macros-by-example)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a060ed2 into rust-lang:master Jan 5, 2024
11 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Jan 5, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 5, 2024
Rollup merge of rust-lang#119622 - Nadrieril:never_patterns_macros, r=compiler-errors

never patterns: Document behavior of never patterns with macros-by-example

`never_patterns` makes `!` parse as a pattern so I was worried about breaking macros-by-example matching. Turns out we're fine because the cases that now match `$p:pat` used to error in the past. The only tricky case is `!` by itself, which backwards-compatibly doesn't match `$p:pat`. I have no idea why tho, I didn't think of that when I was implementing parsing 😅.

This adds tests so we don't regress the current behavior.

r? `@compiler-errors`
@Nadrieril Nadrieril deleted the never_patterns_macros branch January 6, 2024 00:05
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, ..) F-never_patterns `#![feature(never_patterns)]` 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.

5 participants