num-derive icon indicating copy to clipboard operation
num-derive copied to clipboard

Compilation fails when using the -Z build-std option

Open mikeleany opened this issue 3 years ago • 2 comments

Compilation fails when i128 and u128 aren't supported. For example, when compiling a crate with these options: -Z build-std=core,alloc,compiler_builtins --target=x86_64-unknown-uefi.

error[E0407]: method `from_i128` is not a member of trait `_num_traits::FromPrimitive`
   --> src/x86_64.rs:112:62
    |
112 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, FromPrimitive, ToPrimitive)]
    |                                                              ^^^^^^^^^^^^^ not a member of trait `_num_traits::FromPrimitive`
    |
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0407]: method `from_u128` is not a member of trait `_num_traits::FromPrimitive`
   --> src/x86_64.rs:112:62
    |
112 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, FromPrimitive, ToPrimitive)]
    |                                                              ^^^^^^^^^^^^^ not a member of trait `_num_traits::FromPrimitive`
    |
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0407]: method `to_i128` is not a member of trait `_num_traits::ToPrimitive`
   --> src/x86_64.rs:112:77
    |
112 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, FromPrimitive, ToPrimitive)]
    |                                                                             ^^^^^^^^^^^ not a member of trait `_num_traits::ToPrimitive`
    |
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0407]: method `to_u128` is not a member of trait `_num_traits::ToPrimitive`
   --> src/x86_64.rs:112:77
    |
112 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, FromPrimitive, ToPrimitive)]
    |                                                                             ^^^^^^^^^^^ not a member of trait `_num_traits::ToPrimitive`
    |
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

Pull request #45 has been submitted to correct this issue.

mikeleany avatar Apr 12 '21 22:04 mikeleany

i128 should be supported for all versions of rustc currently supported by num-derive, but num-traits supports older versions that might not. The real failure is that autocfg doesn't work with -Z build-std: https://github.com/cuviper/autocfg/issues/34

If you enable the cargo-level i128 feature of num-traits, that should bypass autocfg detection.

cuviper avatar Apr 13 '21 19:04 cuviper

OK. That makes sense. Adding the i128 feature on num-traits does indeed resolve the issue.

mikeleany avatar Apr 14 '21 03:04 mikeleany