rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

Special case `matches!` macro

Open ytmimi opened this issue 3 years ago • 5 comments

Closes #4462 Closes #5547 Closes #5709 Closes #5860 Closes #6650 Closes #6714

Related / duplicate issues #4885 #5176

This PR adds support to parse and format the arguments of the matches! macro. Now matches! formatting more closely resembles match expressions. This update introduces breaking formatting changes and is only supported when formatting with style_edition=2027.

r? @calebcartwright

I've done my best to logically group commits and I think this PR would be best reviewed 1 commit at a time.

ytmimi avatar Oct 01 '22 17:10 ytmimi

I feel like we discussed this a tad offline some time back, but probably worth posting here too that I think a big consideration around this is whether it needs to be version gated.

A question i've had teed up to the style team for a while is if/how macro calls should have style guide prescriptions or whether it's going to be something completely deferred to rustfmt.

In either case, I suspect it's highly likely this will need to be gated, and could perhaps become the new default as part of the 2024 style edition

calebcartwright avatar Jun 19 '23 15:06 calebcartwright

note to self, add a test case for #5860

ytmimi avatar Jul 31 '23 16:07 ytmimi

Sorry for the bump, but there hasn't been any public news on this for almost a year now. Have there been any discussions or anything about whether to include this in the 2024 edition or what the next steps are here?

cynecx avatar Jun 12 '24 15:06 cynecx

Sorry for the bump, but there hasn't been any public news on this for almost a year now. Have there been any discussions or anything about whether to include this in the 2024 edition or what the next steps are here?

This isn't something that the team has discussed in quite some time so I don't have any updated to share from rustfmt. To the best of my knowledge the style-team has had some discussions on the 2024 edition, and these are the tracking issues for rustfmt.

ytmimi avatar Jun 12 '24 16:06 ytmimi

Hi, I also found this bug, which is produced when two ranges are in a matches!, separated by |. I don't think it's a duplicate because it's specific to ranges (when you remove a range from the code, it works).

freerig avatar Oct 25 '25 15:10 freerig