Skip to content

Error about missing From impl when using try_from #61196

Open
@oli-obk

Description

@oli-obk

There are probably some generic trait implementations that cause rustc to follow this line of reasoning.

use std::convert::TryFrom;

fn main() {
    f64::try_from(4usize);
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `f64: std::convert::From<usize>` is not satisfied
 --> src/main.rs:4:5
  |
4 |     f64::try_from(4usize);
  |     ^^^^^^^^^^^^^ the trait `std::convert::From<usize>` is not implemented for `f64`
  |
  = help: the following implementations were found:
            <f64 as std::convert::From<f32>>
            <f64 as std::convert::From<i16>>
            <f64 as std::convert::From<i32>>
            <f64 as std::convert::From<i8>>
          and 3 others
  = note: required because of the requirements on the impl of `std::convert::Into<f64>` for `usize`
  = note: required because of the requirements on the impl of `std::convert::TryFrom<usize>` for `f64`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
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-trait-systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.F-on_unimplementedError messages that can be tackled with `#[rustc_on_unimplemented]`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