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

Simplify some iterator combinators #105541

Merged
merged 2 commits into from
Jan 4, 2023
Merged

Conversation

compiler-errors
Copy link
Member

Saw a flat_map().next() instead of a find_map() in some method probe code, so did a quick search for some similar usages.

@compiler-errors compiler-errors added the C-cleanup Category: PRs that clean code up or issues documenting cleanup. label Dec 10, 2022
@rustbot
Copy link
Collaborator

rustbot commented Dec 10, 2022

r? @cjgillot

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 10, 2022
@rustbot
Copy link
Collaborator

rustbot commented Dec 10, 2022

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo

@leonardo-m
Copy link

Is Clippy able to catch most of this stuff? :)

@compiler-errors
Copy link
Member Author

No idea!

@compiler-errors
Copy link
Member Author

@leonardo-m no -- clippy doesn't trigger on this:

fn main() {
    let x = vec![()];
    x.into_iter().flat_map(|_| Some(1)).next();
    // ^ should probably suggest `find_map`.
}

@matthiaskrgr
Copy link
Member

https://github.com/rust-lang/rust-clippy/issues/new?assignees=&labels=A-lint&template=new_lint.yml :>

@compiler-errors
Copy link
Member Author

So flat_map() over Option<_> is a pedantic lint already that suggests using filter_map, and then filter_map(..).next() is also a lint. So I'm not sure there's much else to suggest for clippy!

@vacuus
Copy link
Contributor

vacuus commented Dec 11, 2022

In compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs, you can change .any(..) to .all(..) and remove both negations. Is Clippy missing this?

@SkiFire13
Copy link
Contributor

In compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs, you can change .any(..) to .all(..) and remove both negations. Is Clippy missing this?

Note that there's also an && in the middle between two negations, so you need to remove all three negations and change the && to a ||. I guess that's too much for clippy.

Copy link
Contributor

@cjgillot cjgillot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a well-deserved simplifications. A few complementary ideas.

@cjgillot cjgillot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 25, 2022
@compiler-errors compiler-errors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 27, 2022
Copy link
Contributor

@cjgillot cjgillot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few extra API nits and r=me.

@bors
Copy link
Contributor

bors commented Jan 4, 2023

☔ The latest upstream changes (presumably #105752) made this pull request unmergeable. Please resolve the merge conflicts.

@compiler-errors
Copy link
Member Author

Addressed comments in static_impl_trait.rs.

@bors r=cjgillot

@bors
Copy link
Contributor

bors commented Jan 4, 2023

📌 Commit 2baee88 has been approved by cjgillot

It is now in the queue for this repository.

@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 Jan 4, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 4, 2023
…mpiler-errors

Rollup of 8 pull requests

Successful merges:

 - rust-lang#104748 (Ensure `lld` is supported with `download-ci-llvm`)
 - rust-lang#105541 (Simplify some iterator combinators)
 - rust-lang#106045 (default OOM handler: use non-unwinding panic, to match std handler)
 - rust-lang#106157 (Don't trim path for `unsafe_op_in_unsafe_fn` lints)
 - rust-lang#106353 (Reduce spans for `unsafe impl` errors)
 - rust-lang#106381 (Jsondoclint: Add `--verbose` and `--json-output` options)
 - rust-lang#106411 (rustdoc: remove legacy font-feature-settings CSS)
 - rust-lang#106414 (Add cuviper to the review rotation for libs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c56d8ed into rust-lang:master Jan 4, 2023
@rustbot rustbot added this to the 1.68.0 milestone Jan 4, 2023
@compiler-errors compiler-errors deleted the iter-comb branch August 11, 2023 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-cleanup Category: PRs that clean code up or issues documenting cleanup. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants