Skip to content
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

Merged
merged 1 commit into from
Sep 15, 2018
Merged

A few cleanups for hir #54151

merged 1 commit into from
Sep 15, 2018

Conversation

ljedrz
Copy link
Contributor

@ljedrz ljedrz commented Sep 12, 2018

  • 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 maps to cloned()
  • use unwrap_or_else and ok when applicable
  • a few other minor readability improvements
  • whitespace fixes

@rust-highfive
Copy link
Collaborator

r? @michaelwoerister

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 12, 2018
NestedVisitorMap::All(map) => Some(map),
_ => None
Copy link
Member

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.

hir::Defaultness::Default { .. } => self.word_nbsp("default")?,
hir::Defaultness::Final => (),
if let hir::Defaultness::Default { .. } = defaultness {
self.word_nbsp("default")?
Copy link
Member

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.

hir::IsAsync::NotAsync => {}
hir::IsAsync::Async => self.word_nbsp("async")?,
if let hir::IsAsync::Async = header.asyncness {
self.word_nbsp("async")?
Copy link
Member

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.

@michaelwoerister
Copy link
Member

Thanks for the PR, @ljedrz! I've lot some comments in the code.

@ljedrz
Copy link
Contributor Author

ljedrz commented Sep 12, 2018

@michaelwoerister thanks, comments addressed.

@ljedrz
Copy link
Contributor Author

ljedrz commented Sep 14, 2018

r? @michaelwoerister

@michaelwoerister
Copy link
Member

Thanks, @ljedrz!

@bors r+

@bors
Copy link
Contributor

bors commented Sep 14, 2018

📌 Commit 2919ecd has been approved by michaelwoerister

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 14, 2018
@bors
Copy link
Contributor

bors commented Sep 15, 2018

⌛ Testing commit 2919ecd with merge ed45f9c...

bors added a commit that referenced this pull request Sep 15, 2018
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
@bors
Copy link
Contributor

bors commented Sep 15, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: michaelwoerister
Pushing ed45f9c to master...

@bors bors merged commit 2919ecd into rust-lang:master Sep 15, 2018
@ljedrz ljedrz deleted the cleanup_hir branch September 15, 2018 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants