Skip to content

Support if-let guards in matches macros by using :guard matcher#156025

Open
SpriteOvO wants to merge 2 commits intorust-lang:mainfrom
SpriteOvO:matches-guard
Open

Support if-let guards in matches macros by using :guard matcher#156025
SpriteOvO wants to merge 2 commits intorust-lang:mainfrom
SpriteOvO:matches-guard

Conversation

@SpriteOvO
Copy link
Copy Markdown
Member

@SpriteOvO SpriteOvO commented May 1, 2026

Tracking issue #153104.

This PR replaces the original if $guard:expr with new matcher $guard:guard in macros matches! and assert_matches! to support the use of if-let guards syntax in these macros. This syntax is already stable in #141295 for match arms.

Please note that this PR directly applies :guard to macros that are already stable, so the support for if-let guards in these macros is instantly stable.

When using these macros that accept :guard, users will not be required to use nightly and enable #![feature(macro_guard_matcher)]. However, when defining macros with :guard, nightly and #![feature(macro_guard_matcher)] are still required. Therefore, I think a Crater run is needed.

cc @programmerjake
r? libs

@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 1, 2026
@SpriteOvO
Copy link
Copy Markdown
Member Author

Please note that this PR directly applies :guard to macros that are already stable, so the support for if-let guards in these macros is instantly stable.

When using these macros that accept :guard, users will not be required to use nightly and enable #![feature(macro_guard_matcher)]. However, when defining macros with :guard, nightly and #![feature(macro_guard_matcher)] are still required. Therefore, I think a Crater run is needed.

Alternatively, to be more safe, we only provide the :guard version of macros when users activate macro_guard_matcher, otherwise falling back to the original if $e:expr version. But I couldn't find a way to write something like #[cfg(unstable_feature = "macro_guard_matcher")] in stdlib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants