Skip to content

Type inference asks for annotations that are already present #69214

Closed
@alecmocatta

Description

@alecmocatta
use std::convert::TryInto;

fn main() {
    let _: usize = Some(0usize).map(|host: usize| 0usize).unwrap() + 0usize.try_into().unwrap();
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0284]: type annotations needed for `usize`
 --> src/main.rs:4:38
  |
4 |     let _: usize = Some(0usize).map(|host: usize| 0usize).unwrap() + 0usize.try_into().unwrap();
  |                                      ^^^^ consider giving this closure parameter a type
  |
  = note: cannot resolve `<usize as std::ops::Add<_>>::Output == usize`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0284`.
error: could not compile `playground`.

To learn more, run the command again with --verbose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-inferenceArea: Type inferenceC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions