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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

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
obeis committed Feb 23, 2023
commit 99344a8b3231925bc52190b7e9c18a597c54ca90
13 changes: 13 additions & 0 deletions tests/ui/lint/issue-106991.rs
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();
}
11 changes: 11 additions & 0 deletions tests/ui/lint/issue-106991.stderr
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`
Comment on lines +1 to +7
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.


error: aborting due to previous error

For more information about this error, try `rustc --explain E0271`.