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

Lint against Iterator::map receiving a callable that returns () #107890

Merged
merged 5 commits into from
Feb 26, 2023

Conversation

obeis
Copy link
Contributor

@obeis obeis commented Feb 10, 2023

Close #106991

@rustbot
Copy link
Collaborator

rustbot commented Feb 10, 2023

r? @cjgillot

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

@rustbot rustbot added A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic 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 Feb 10, 2023
@rustbot
Copy link
Collaborator

rustbot commented Feb 10, 2023

rustc_error_messages was changed

cc @davidtwco, @compiler-errors, @JohnTitor, @TaKO8Ki

compiler/rustc_lint/src/map_unit_fn.rs Show resolved Hide resolved
compiler/rustc_lint/src/map_unit_fn.rs Outdated Show resolved Hide resolved
compiler/rustc_lint/src/map_unit_fn.rs Outdated Show resolved Hide resolved
compiler/rustc_lint/src/map_unit_fn.rs Outdated Show resolved Hide resolved
compiler/rustc_lint/src/map_unit_fn.rs Outdated Show resolved Hide resolved
compiler/rustc_lint/src/map_unit_fn.rs Outdated Show resolved Hide resolved
compiler/rustc_lint/src/map_unit_fn.rs Outdated Show resolved Hide resolved
@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 Feb 10, 2023
@cjgillot
Copy link
Contributor

cjgillot commented Feb 10, 2023

Also, I wonder if we should just make Iterator::map a #[must_use] method, and integrate the suggestion into the must-use lint?

@rust-log-analyzer

This comment has been minimized.

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.

I still have my question about #[must_use].

compiler/rustc_lint/src/map_unit_fn.rs Outdated Show resolved Hide resolved
compiler/rustc_lint/src/map_unit_fn.rs Outdated Show resolved Hide resolved
compiler/rustc_lint/src/map_unit_fn.rs Show resolved Hide resolved
@rust-log-analyzer

This comment has been minimized.

@scottmcm
Copy link
Member

scottmcm commented Feb 14, 2023

If this were to go in must_use, it wouldn't go on the function, but as an update to

#[must_use = "iterators are lazy and do nothing unless consumed"]

@rustbot
Copy link
Collaborator

rustbot commented Feb 16, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@obeis obeis force-pushed the mapping-to-unit branch 6 times, most recently from cb6b545 to b6b121e Compare February 17, 2023 11:00
@obeis
Copy link
Contributor Author

obeis commented Feb 17, 2023

@rustbot ready

@rustbot rustbot 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 Feb 17, 2023
@obeis obeis requested a review from cjgillot February 17, 2023 15:03
@cjgillot
Copy link
Contributor

Could you add a test that the example in #106991 (comment) diagnoses both the type error and the lint?

There is a redundancy between the unused_must_use message (see https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=e7043cad0b9bfadca3718b3843ed725f) and this lint. Is there any way to avoid this?

@bors
Copy link
Contributor

bors commented Feb 22, 2023

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

@rust-log-analyzer

This comment has been minimized.

@obeis obeis force-pushed the mapping-to-unit branch 3 times, most recently from cac8701 to a97f486 Compare February 23, 2023 08:19
@rust-log-analyzer

This comment has been minimized.

@cjgillot
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Feb 25, 2023

📌 Commit 99344a8 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 Feb 25, 2023
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Feb 25, 2023
Lint against `Iterator::map` receiving a callable that returns `()`

Close rust-lang#106991
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Feb 25, 2023
Lint against `Iterator::map` receiving a callable that returns `()`

Close rust-lang#106991
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 26, 2023
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#107062 (Do some cleanup of doc/index.md)
 - rust-lang#107890 (Lint against `Iterator::map` receiving a callable that returns `()`)
 - rust-lang#108431 (Add regression test for rust-lang#107918)
 - rust-lang#108432 (test: drop unused deps)
 - rust-lang#108436 (make "proc macro panicked" translatable)
 - rust-lang#108444 (docs/test: add UI test and docs for `E0476`)
 - rust-lang#108449 (Do not lint ineffective unstable trait impl for unresolved trait)
 - rust-lang#108456 (Complete migrating `ast_passes` to derive diagnostics)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit fa10a21 into rust-lang:master Feb 26, 2023
@rustbot rustbot added this to the 1.69.0 milestone Feb 26, 2023
Comment on lines +1 to +7
error[E0271]: expected `foo` to be a fn item that returns `i32`, but it returns `()`
--> $DIR/issue-106991.rs:5:13
|
LL | fn bar() -> impl Iterator<Item = i32> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `i32`
|
= note: required for `Map<std::slice::IterMut<'_, Vec<u8>>, for<'a> fn(&'a mut Vec<u8>) {foo}>` to implement `Iterator`
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a case where we should be doing more than we are now. A similar explanation to the lint's would be necessary to properly convey to users what the problem was. At least pointing at the return expression with nothing else would be an improvement.

@obeis obeis deleted the mapping-to-unit branch May 13, 2023 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic 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.

Lint against Iterator::map receiving a callable that returns ()
7 participants