Skip to content

Type inference fails even though all types are known #58517

Open
@SeeSpring

Description

@SeeSpring

The following code fails to compile, even though all types are known
https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=8de9e57e8de5cd8f2896f422d693f453

pub fn f(s: &str) {
    let mut it = s.split(|c: char| c == ',').fuse();
    let t = it.next().unwrap().parse::<usize>().unwrap();
}
   Compiling playground v0.0.1 (/playground)
error[E0282]: type annotations needed
 --> src/main.rs:3:13
  |
3 |     let t = it.next().unwrap().parse::<usize>().unwrap();
  |             ^^^^^^^^^^^^^^^^^^ cannot infer type for `T`
  |
  = note: type must be known at this point

error: aborting due to previous error

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

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

Metadata

Metadata

Assignees

Labels

A-inferenceArea: Type inferenceC-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions