Skip to content

Confusing error message with str::parse #70065

Open
@Aaron1011

Description

@Aaron1011

The following code:

fn bar() -> Result<(), std::num::ParseIntError> {
    let a = "Hello".parse()?;
    Ok(())
}

fn main() {}

gives the following error message:

error[E0277]: the trait bound `(): std::str::FromStr` is not satisfied
 --> src/main.rs:2:21
  |
2 |     let a = "Hello".parse()?;
  |                     ^^^^^ the trait `std::str::FromStr` is not implemented for `()`

error: aborting due to previous error

The bound (): std::str::FromStr appears seemingly out of thin air. We should explain where the type () and trait std::str::FromStr come from.

The () appears to be produced by never-type fallback, which was quite surprising to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.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