Skip to content

E0308 hint suggests adding a return type to a closure #128561

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

Open
lolbinarycat opened this issue Aug 2, 2024 · 0 comments · May be fixed by #135562
Open

E0308 hint suggests adding a return type to a closure #128561

lolbinarycat opened this issue Aug 2, 2024 · 0 comments · May be fixed by #135562
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lolbinarycat
Copy link
Contributor

Code

fn main() {
    b"abc".iter().for_each(|x| dbg!(x))
}

Current output

error[E0308]: mismatched types
 --> src/main.rs:2:32
  |
2 |     b"abc".iter().for_each(|x| dbg!(x))
  |                               -^^^^^^^ expected `()`, found `&u8`
  |                               |
  |                               help: try adding a return type: `-> &u8`
  |

Desired output

error[E0308]: mismatched types
 --> src/main.rs:2:32
  |
2 |     b"abc".iter().for_each(|x| dbg!(x))
  |                               -^^^^^^^ expected `()`, found `&u8`
  |                               |
  |                               help: try ignoring this value: `_ = dbg!(x)`

Rationale and extra context

closures have their return type inferred if not specified, so adding a return type to a closure will never fix a type error.

Other cases

No response

Rust Version

1.80.0

Anything else?

No response

@lolbinarycat lolbinarycat added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 2, 2024
@chenyukang chenyukang self-assigned this Aug 3, 2024
@chenyukang chenyukang linked a pull request Jan 16, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants