Repository navigation
Tracking issue for the matches! macro #65721
Copy link
Copy link
Closed
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Description
#65479 adds this macro to the prelude:
#[macro_export]
macro_rules! matches {
($expression:expr, $( $pattern:pat )|+ $( if $guard: expr )?) => {
match $expression {
$( $pattern )|+ $( if $guard )? => true,
_ => false
}
}
}Example usage:
let foo = 'f';
assert!(matches!(foo, 'A'..='Z' | 'a'..='z'));
let bar = Some(4);
assert!(matches!(bar, Some(x) if x > 2));Reacted by Mark Yan
Reacted by Robin Lambertz, leo60228, Dylan MacKenzie, DutchGhost, mark, Robin Stocker, Jonas Platte, Jon Gjengset, Deyan Ginev, Shirshak and 18 more
Reacted by Stepan Koltsov and 寒冬
Metadata
Metadata
Assignees
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)B-unstableBlocker: Implemented in the nightly compiler and unstable.Blocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-api[DEPRECATED; DO NOT USE][DEPRECATED; DO NOT USE]disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Activity
SimonSapin commentedon Oct 25, 2019
This caused a regression in html5ever because the prelude macro becomes ambiguous with a macro that was brought into scope by a glob import: servo/html5ever#402
@rust-lang/lang, could we make that situation not an error? It seems that we could resolve the ambiguity in favor of the glob import since it is "more local" to the rest of the code in the module.
eddyb commentedon Oct 25, 2019
cc @petrochenkov
petrochenkov commentedon Oct 25, 2019
For macros (and imports) it's hard to do.
To remove the ambiguity error we need to prove that with any expansion order and any import resolution order
matchesmaterializes from theuse mac::*glob "not later" than from prelude.Otherwise we'll get code that compiles today but not tomorrow depending on random implementation details. (Making e.g. things like this impossible.)
SimonSapin commentedon Oct 25, 2019
I have a memory of a change made to treat differently during name resolution items that are unstable, so that new standard library addition can (at first) warn instead of error when they conflict with existing code. However I couldn’t find this again. Maybe it was only for traits?
petrochenkov commentedon Oct 25, 2019
Yeah, that was for method resolution.
SimonSapin commentedon Oct 25, 2019
Would a similar special case for unstable prelude items make sense?
SimonSapin commentedon Dec 16, 2019
The 1.42 cycle starts soon. Any objection?
@rfcbot fcp merge
rfcbot commentedon Dec 16, 2019
Team member @SimonSapin has proposed to merge this. The next step is review by the rest of the tagged team members:
No concerns currently listed.
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!
See this document for info about what commands tagged team members can give me.
5 remaining items
rfcbot commentedon Dec 16, 2019
🔔 This is now entering its final comment period, as per the review above. 🔔
rfcbot commentedon Dec 26, 2019
The final comment period, with a disposition to merge, as per the review above, is now complete.
As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.
The RFC will be merged soon.
Stabilize the `matches!` macro
Rollup merge of rust-lang#67659 - SimonSapin:matches, r=rkruppe
jonhoo commentedon Dec 28, 2019
How do we feel about giving this the "relnotes" tag?
tesuji commentedon Dec 28, 2019
Already on the stabilized PR: #67659
SimonSapin commentedon Dec 28, 2019
@jonhoo I thought
RELEASES.mdlisted all new(ly-stabilized) APIs? I addedrelnotesto the stabilization PR on that basis. That’s what the label is for, right? This is not to say this should necessarily be mentioned in the release blog post.danielhenrymantilla commentedon Mar 6, 2020
Could
matches!be enhanced to also accept a leading|?This would be consistent with the syntax of Rust accepting it where fallible patterns are accepted:
downgrade rusqlite dependency from 0.24.2 to 0.23.1 for Buster
Updated rust to fix build and merged in dependabot PRs
release: 0.8.0 (#162)