Skip to content

Expand E0271 on return type - #164720

Open
estebank wants to merge 2 commits into
rust-lang:mainfrom
estebank:issue-106991
Open

estebank wants to merge 2 commits into
rust-lang:mainfrom
estebank:issue-106991

Conversation

@estebank

@estebank estebank commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Point at returned expression(s) when an equality projection fails on the return type. Point at each component of an method chain to indicate where expected assoc type diverged. Close the gap in output quality between the current and next solver.

error[E0271]: expected `Map<IterMut<'_, Vec<u8>>, fn(&mut Vec<u8>) {foo}>` to be an iterator that yields `i32`, but it yields `()`
  --> $DIR/issue-106991.rs:8:13
   |
LL | fn bar() -> impl Iterator<Item = i32> {
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `()`
...
LL |     x.iter_mut().map(foo)
   |     --------------------- `Map<std::slice::IterMut<'_, Vec<u8>>, for<'a> fn(&'a mut Vec<u8>) {foo}>` returned here
   |
note: the method call chain might not have had the expected associated types
  --> $DIR/issue-106991.rs:12:18
   |
LL |     let mut x: Vec<Vec<u8>> = vec![vec![0, 2, 1], vec![5, 4, 3]];
   |                               ---------------------------------- this expression has type `Vec<Vec<u8>>`
LL |     x.iter_mut().map(foo)
   |       ---------- ^^^^^^^^ `Iterator::Item` changed to `()` here
   |       |
   |       `Iterator::Item` is `&mut Vec<u8>` here

Fix #106991. Drive by fix of incorrectly pointing at argument when error meant to point at return type (because logic didn't account for methods with receivers).

@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 Oct 22, 2026
@rustbot

rustbot commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

r? @jackh726

rustbot has assigned @jackh726.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 77 candidates
  • Random selection from 20 candidates

@rust-bors

This comment has been minimized.

```
error[E0271]: expected `Map<IterMut<'_, Vec<u8>>, fn(&mut Vec<u8>) {foo}>` to be an iterator that yields `i32`, but it yields `()`
  --> $DIR/issue-106991.rs:8:13
   |
LL | fn bar() -> impl Iterator<Item = i32> {
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `()`
...
LL |     x.iter_mut().map(foo)
   |     --------------------- `Map<std::slice::IterMut<'_, Vec<u8>>, for<'a> fn(&'a mut Vec<u8>) {foo}>` returned here
```
@rustbot

rustbot commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer

This comment has been minimized.

…urned expr

```
error[E0271]: expected `Map<IterMut<'_, Vec<u8>>, fn(&mut Vec<u8>) {foo}>` to be an iterator that yields `i32`, but it yields `()`
  --> $DIR/issue-106991.rs:8:13
   |
LL | fn bar() -> impl Iterator<Item = i32> {
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `()`
...
LL |     x.iter_mut().map(foo)
   |     --------------------- `Map<std::slice::IterMut<'_, Vec<u8>>, for<'a> fn(&'a mut Vec<u8>) {foo}>` returned here
   |
note: the method call chain might not have had the expected associated types
  --> $DIR/issue-106991.rs:12:18
   |
LL |     let mut x: Vec<Vec<u8>> = vec![vec![0, 2, 1], vec![5, 4, 3]];
   |                               ---------------------------------- this expression has type `Vec<Vec<u8>>`
LL |     x.iter_mut().map(foo)
   |       ---------- ^^^^^^^^ `Iterator::Item` changed to `()` here
   |       |
   |       `Iterator::Item` is `&mut Vec<u8>` here
```

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants