Skip to content

Conversation

yotamofek
Copy link
Contributor

Split out from #135732 according to #135732 ,
same thing but just for the compiler:

The usage of map_or(bool, ...) is really hard to understand IMHO.
This PR simply uses clippy (with --fix) to replace that with is_{some_and|none_or|ok_and}.
(no manual modifications were made, just machine applicable clippy fixes and then fmt)

r? @compiler-errors

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Jan 19, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jan 19, 2025

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri, @rust-lang/wg-const-eval

Some changes occurred in coverage instrumentation.

cc @Zalathar

@yotamofek yotamofek changed the title Run clippy --fix for unnecessary_map_or lint Replace usages of map_or(bool, ...) with is_{some_and|none_or|ok_and} Jan 19, 2025
.iter()
.find(|a| a.doc_str().is_some())
.map_or(true, |a| a.style() == ast::AttrStyle::Inner)
attrs.iter().find(|a| a.doc_str().is_some()).is_none_or(|a| a.style() == ast::AttrStyle::Inner)
Copy link
Member

Choose a reason for hiding this comment

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

the logic here could be simplified. is this not just attrs.iter().any(|a| a.doc_str().is_some() && a.style() == ast::AttrStyle::Inner)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Err.. I don't think so, the original logic returns true if find() returns None. No?
Can't wrap my head right now around what's happening here, but I definitely agree it's not very readable.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, right. What the heck.

@yotamofek
Copy link
Contributor Author

@compiler-errors my thought was to not do any manual cleanups, just let clippy do it's thing, but if I'm already doing some extra work on top of it I cleaned up a bunch of other stuff.
It's in a separate commit so it's easier to separate the automatic fixes from the manual ones.

@compiler-errors
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jan 19, 2025

📌 Commit 1951d86 has been approved by compiler-errors

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 19, 2025
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jan 19, 2025
…compiler-errors

Replace usages of `map_or(bool, ...)` with `is_{some_and|none_or|ok_and}`

Split out from rust-lang#135732 according to rust-lang#135732 ,
same thing but just for the compiler:

> The usage of `map_or(bool, ...)` is really hard to understand IMHO.
> This PR simply uses clippy (with `--fix`) to replace that with `is_{some_and|none_or|ok_and}`.
> (no manual modifications were made, just machine applicable clippy fixes and then fmt)

r? `@compiler-errors`
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 19, 2025
…llaumeGomez

Rollup of 8 pull requests

Successful merges:

 - rust-lang#135310 (Always force non-trimming of path in `unreachable_patterns` lint)
 - rust-lang#135446 (further improve panic_immediate_abort by removing rtprintpanic! messages)
 - rust-lang#135491 (Remove dead rustc_allowed_through_unstable_modules for std::os::fd contents)
 - rust-lang#135542 (Add the concrete syntax for precise capturing to 1.82 release notes.)
 - rust-lang#135700 (Emit single privacy error for struct literal with multiple private fields and add test for `default_field_values` privacy)
 - rust-lang#135729 (Add debug assertions to compiler profile)
 - rust-lang#135736 (rustdoc: Fix flaky doctest test)
 - rust-lang#135738 (Replace usages of `map_or(bool, ...)` with `is_{some_and|none_or|ok_and}`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 20, 2025
Rollup of 7 pull requests

Successful merges:

 - rust-lang#135542 (Add the concrete syntax for precise capturing to 1.82 release notes.)
 - rust-lang#135700 (Emit single privacy error for struct literal with multiple private fields and add test for `default_field_values` privacy)
 - rust-lang#135722 (make it possible to use ci-rustc on tarball sources)
 - rust-lang#135729 (Add debug assertions to compiler profile)
 - rust-lang#135736 (rustdoc: Fix flaky doctest test)
 - rust-lang#135738 (Replace usages of `map_or(bool, ...)` with `is_{some_and|none_or|ok_and}`)
 - rust-lang#135747 (Rename FileName::QuoteExpansion to CfgSpec)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 20, 2025
Rollup of 7 pull requests

Successful merges:

 - rust-lang#135542 (Add the concrete syntax for precise capturing to 1.82 release notes.)
 - rust-lang#135700 (Emit single privacy error for struct literal with multiple private fields and add test for `default_field_values` privacy)
 - rust-lang#135722 (make it possible to use ci-rustc on tarball sources)
 - rust-lang#135729 (Add debug assertions to compiler profile)
 - rust-lang#135736 (rustdoc: Fix flaky doctest test)
 - rust-lang#135738 (Replace usages of `map_or(bool, ...)` with `is_{some_and|none_or|ok_and}`)
 - rust-lang#135747 (Rename FileName::QuoteExpansion to CfgSpec)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 20, 2025
Rollup of 7 pull requests

Successful merges:

 - rust-lang#135542 (Add the concrete syntax for precise capturing to 1.82 release notes.)
 - rust-lang#135700 (Emit single privacy error for struct literal with multiple private fields and add test for `default_field_values` privacy)
 - rust-lang#135722 (make it possible to use ci-rustc on tarball sources)
 - rust-lang#135729 (Add debug assertions to compiler profile)
 - rust-lang#135736 (rustdoc: Fix flaky doctest test)
 - rust-lang#135738 (Replace usages of `map_or(bool, ...)` with `is_{some_and|none_or|ok_and}`)
 - rust-lang#135747 (Rename FileName::QuoteExpansion to CfgSpec)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit f3f21ae into rust-lang:master Jan 20, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Jan 20, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 20, 2025
Rollup merge of rust-lang#135738 - yotamofek:map_or_true-compiler, r=compiler-errors

Replace usages of `map_or(bool, ...)` with `is_{some_and|none_or|ok_and}`

Split out from rust-lang#135732 according to rust-lang#135732 ,
same thing but just for the compiler:

> The usage of `map_or(bool, ...)` is really hard to understand IMHO.
> This PR simply uses clippy (with `--fix`) to replace that with `is_{some_and|none_or|ok_and}`.
> (no manual modifications were made, just machine applicable clippy fixes and then fmt)

r? ``@compiler-errors``
@yotamofek yotamofek deleted the map_or_true-compiler branch January 20, 2025 17:28
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants