Skip to content

Rustc fails to suggest an easy fix; instead provides a confusing error message #72124

Closed
@digitalnomd

Description

@digitalnomd

The following code produces an unexpected error message:

test.split_whitespace().next().ok_or_else(|| {
    format_err!("Couldn't split the test string");
})?;

I expected the compiler to give me a warning like "ok_or_else needs to return the trait std::error::Error. Instead you are returning (). Suggestion: remove the ;.

Instead, I received the following error message which was hard to parse:

 |     })?;
  |       ^ the trait `std::error::Error` is not implemented for `()`
  |
  = note: required because of the requirements on the impl of `failure::Fail` for `()`
  = note: required because of the requirements on the impl of `std::convert::From<()>` for `failure::Error`
  = note: required by `std::convert::From::from`

The rust compiler version that I am using is 1.43.1. This behavior also exists within the beta and nightly versions. I also created an example using the rust-playground here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=33e42842b0d6385ea5704e323c113e7f.

Thanks again!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.D-papercutDiagnostics: An error or lint that needs small tweaks.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