-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a914f37
Add lint against `Iterator::map` receiving a callable that returns `()`
obeis ddd7d10
Add ui test for `map_unit_fn` lint
obeis a87443a
Emit `map_unit_fn` lint in closure case
obeis b93d545
Add ui test for `map_unit_fn` lint in closure case
obeis 99344a8
Add ui test for `E0271` error
obeis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev
Previous commit
Add ui test for
E0271
error
- Loading branch information
commit 99344a8b3231925bc52190b7e9c18a597c54ca90
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
fn foo(items: &mut Vec<u8>) { | ||
items.sort(); | ||
} | ||
|
||
fn bar() -> impl Iterator<Item = i32> { | ||
//~^ ERROR expected `foo` to be a fn item that returns `i32`, but it returns `()` [E0271] | ||
let mut x: Vec<Vec<u8>> = vec![vec![0, 2, 1], vec![5, 4, 3]]; | ||
x.iter_mut().map(foo) | ||
} | ||
|
||
fn main() { | ||
bar(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
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` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0271`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.