-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Reduce boilerplate with the matches! macro #76995
Conversation
Replaces simple bool `match`es of the form match $expr { $pattern => true _ => false } and their inverse with invocations of the matches! macro.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @varkor (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Does this affect compile time of compiler? |
@lzutao It's only a macro expansion, I doubt it would have any measurable effect on the compiler build. |
Since macro expansion already happens with
Not perfectly scientific but hopefully this is enough to address your compile time concerns. |
I don't think we should worry about trivial compile time +/- like a few macros until we start tracking it (hopefully soon!). I felt that the patch as a whole improved readability, and though I am not 100% sure we want to use matches! whenever a boolean output is expected, I think in the cases provided here it made sense to do so for the most part. I was uncertain if we should do so when we want cc @rust-lang/libs if y'all are interested in seeing some real-world examples of matches use or have thoughts on the |
These all seem like improvements to me. I'll wait a while to see if anyone else has an opinion, but otherwise it looks good. |
I feel what @Mark-Simulacrum said regarding Certainly made me check for something like |
@bors r+ rollup Thanks! |
📌 Commit a6ff925 has been approved by |
I think the appearance of |
Rollup of 13 pull requests Successful merges: - rust-lang#76388 (Add a note about the panic behavior of math operations on time objects) - rust-lang#76855 (Revamp rustdoc docs about documentation using `cfg`) - rust-lang#76995 (Reduce boilerplate with the matches! macro) - rust-lang#77228 (Add missing examples for MaybeUninit) - rust-lang#77528 (Avoid unchecked casts in net parser) - rust-lang#77534 (Disallow overriding forbid in same scope) - rust-lang#77555 (Allow anyone to set regression labels) - rust-lang#77558 (Rename bootstrap/defaults/{config.toml.PROFILE => config.PROFILE.toml}) - rust-lang#77559 (Fix rustdoc warnings about invalid Rust syntax) - rust-lang#77560 (Fix LitKind's byte buffer to use refcounted slice) - rust-lang#77573 (Hint doc use convert::identity relative link) - rust-lang#77587 (Fix span for unicode escape suggestion.) - rust-lang#77591 (Record `expansion_that_defined` into crate metadata) Failed merges: r? `@ghost`
Replaces simple bool
match
es of the formand their inverse with invocations of the matches! macro.
Limited to rustc_middle for now to get my feet wet.