-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
A few cleanups for hir #54151
A few cleanups for hir #54151
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
src/librustc/hir/intravisit.rs
Outdated
NestedVisitorMap::All(map) => Some(map), | ||
_ => None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually we try to make match statements exhaustive in order to catch errors when new variants are added.
src/librustc/hir/print.rs
Outdated
hir::Defaultness::Default { .. } => self.word_nbsp("default")?, | ||
hir::Defaultness::Final => (), | ||
if let hir::Defaultness::Default { .. } = defaultness { | ||
self.word_nbsp("default")? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd keep this the old way too. It's good to see all the options listed.
src/librustc/hir/print.rs
Outdated
hir::IsAsync::NotAsync => {} | ||
hir::IsAsync::Async => self.word_nbsp("async")?, | ||
if let hir::IsAsync::Async = header.asyncness { | ||
self.word_nbsp("async")? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same here and constness
above. It's a bit more verbose to list all variants, but also a lot more readable for someone who does not know the code base by heart.
Thanks for the PR, @ljedrz! I've lot some comments in the code. |
@michaelwoerister thanks, comments addressed. |
📌 Commit 2919ecd has been approved by |
A few cleanups for hir - prefer `if let` to `match` when only 1 branch matters - `chain` iterable items that are looped over in sequence - `sort_by_key` instead of `sort_by` when possible - change cloning `map`s to `cloned()` - use `unwrap_or_else` and `ok` when applicable - a few other minor readability improvements - whitespace fixes
☀️ Test successful - status-appveyor, status-travis |
if let
tomatch
when only 1 branch matterschain
iterable items that are looped over in sequencesort_by_key
instead ofsort_by
when possiblemap
s tocloned()
unwrap_or_else
andok
when applicable