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

collapse nested if blocks #9613

Merged
merged 1 commit into from
Aug 6, 2021

Conversation

danieleades
Copy link
Contributor

No description provided.

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Eh2406 (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.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 23, 2021
@alexcrichton
Copy link
Member

Personally I prefer to not blanket do this via the guidance of some external tool. The structure of if/else often reflects the evolution of the code over time and I don't think that collapsing isolated blocks is always a net benefit. In some situations it hinders future refactoring or other future tweaks. Bunching all if conditions together I also find pretty unreadable sometimes.

@danieleades
Copy link
Contributor Author

Personally I prefer to not blanket do this via the guidance of some external tool. The structure of if/else often reflects the evolution of the code over time and I don't think that collapsing isolated blocks is always a net benefit. In some situations it hinders future refactoring or other future tweaks. Bunching all if conditions together I also find pretty unreadable sometimes.

Personally i don't think collapsing the statements makes them less readable, though it's debatable whether it makes them more readable in all cases. It does remove a level of indentation. Also, if another else/if else condition is added later to the same block, there can be ambiguity about whether to add that the the outer or inner scope of the nested statements. it's a small risk, but you eliminate it by collapsing the blocks.

i definitely think collapsing the "if { else {...}}" blocks into "if else {...}" blocks improves readability. there's a couple of examples of that.

there are some ugly ones in there too, for example

 if unit.target.is_cdylib()
                    && !self.compilation.cdylibs.iter().any(|uo| uo.unit == *unit) {
        ...
}

but i don't think this is any less readable than the original-

 if unit.target.is_cdylib() {
                    if !self.compilation.cdylibs.iter().any(|uo| uo.unit == *unit) {
                          ...
                    }

It might be worth naming some of this checks to document what it is they're actually testing. as in,

// as a free function, or a struct method...
fn check_that_thing(cdylibs: ...) -> bool {
   ...
}

 if unit.target.is_cdylib() && check_that_thing(self.compilation.cdylibs) {
    ...
}

@ehuss
Copy link
Contributor

ehuss commented Aug 6, 2021

I'm going to go ahead and merge this, but I want to point out that there is a comment here specifically saying we would prefer to not have PRs fixing clippy lints. They tend to be subjective, or have false positives, or break things. In this case, I don't think this is a significant improvement, but a small reduction in nesting I think is fine.

@bors r+

@bors
Copy link
Collaborator

bors commented Aug 6, 2021

📌 Commit c5da878 has been approved by ehuss

@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 Aug 6, 2021
@bors
Copy link
Collaborator

bors commented Aug 6, 2021

⌛ Testing commit c5da878 with merge e928b62...

@bors
Copy link
Collaborator

bors commented Aug 6, 2021

☀️ Test successful - checks-actions
Approved by: ehuss
Pushing e928b62 to master...

@bors bors merged commit e928b62 into rust-lang:master Aug 6, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Aug 11, 2021
Update cargo

9 commits in cc17afbb0067b1f57d8882640f63b2168d5b7624..b51439fd8b505d4800a257acfecf3c69f81e35cf
2021-08-02 20:28:08 +0000 to 2021-08-09 18:40:05 +0000
- Deduplicate entries in cargo --list (rust-lang/cargo#9773)
- Include aliases with other commands (rust-lang/cargo#9764)
- Add a profile option to select the codegen backend (rust-lang/cargo#9118)
- remove useless conversions (rust-lang/cargo#9617)
- collapse nested if blocks (rust-lang/cargo#9613)
- Refactor fake_file() away from cargo_command tests (rust-lang/cargo#9767)
- Update cargo-platform to 0.1.2 (rust-lang/cargo#9762)
- Bump to the latest jobserver dependency (rust-lang/cargo#9760)
- Fix semver check for rust 1.54.0 (rust-lang/cargo#9763)
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Aug 11, 2021
Update cargo

9 commits in cc17afbb0067b1f57d8882640f63b2168d5b7624..b51439fd8b505d4800a257acfecf3c69f81e35cf
2021-08-02 20:28:08 +0000 to 2021-08-09 18:40:05 +0000
- Deduplicate entries in cargo --list (rust-lang/cargo#9773)
- Include aliases with other commands (rust-lang/cargo#9764)
- Add a profile option to select the codegen backend (rust-lang/cargo#9118)
- remove useless conversions (rust-lang/cargo#9617)
- collapse nested if blocks (rust-lang/cargo#9613)
- Refactor fake_file() away from cargo_command tests (rust-lang/cargo#9767)
- Update cargo-platform to 0.1.2 (rust-lang/cargo#9762)
- Bump to the latest jobserver dependency (rust-lang/cargo#9760)
- Fix semver check for rust 1.54.0 (rust-lang/cargo#9763)
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Aug 12, 2021
Update cargo

9 commits in cc17afbb0067b1f57d8882640f63b2168d5b7624..b51439fd8b505d4800a257acfecf3c69f81e35cf
2021-08-02 20:28:08 +0000 to 2021-08-09 18:40:05 +0000
- Deduplicate entries in cargo --list (rust-lang/cargo#9773)
- Include aliases with other commands (rust-lang/cargo#9764)
- Add a profile option to select the codegen backend (rust-lang/cargo#9118)
- remove useless conversions (rust-lang/cargo#9617)
- collapse nested if blocks (rust-lang/cargo#9613)
- Refactor fake_file() away from cargo_command tests (rust-lang/cargo#9767)
- Update cargo-platform to 0.1.2 (rust-lang/cargo#9762)
- Bump to the latest jobserver dependency (rust-lang/cargo#9760)
- Fix semver check for rust 1.54.0 (rust-lang/cargo#9763)
@ehuss ehuss added this to the 1.56.0 milestone Feb 6, 2022
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.

6 participants