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

Macros are unhygenic

Open rdrpenguin04 opened this issue 3 years ago • 1 comments

When using this alongside the xlang_abi crate, the following error is thrown:

error[E0053]: method `from_u64` has an incompatible type for trait
  --> modules/elf/src/lib.rs:13:10
   |
13 | #[derive(FromPrimitive, ToPrimitive)]
   |          ^^^^^^^^^^^^^
   |          |
   |          expected enum `std::option::Option`, found enum `xlang_abi::option::Option`
   |          help: change the output type to match the trait: `std::option::Option<ProgramHeaderType>`
   |
   = note: expected fn pointer `fn(_) -> std::option::Option<ProgramHeaderType>`
              found fn pointer `fn(_) -> xlang_abi::option::Option<ProgramHeaderType>`
   = note: this error originates in the derive macro `FromPrimitive` (in Nightly builds, run with -Z macro-backtrace for more info)

This can be solved by specifying core::option::Option in any place where Option is used.

rdrpenguin04 avatar Apr 16 '22 19:04 rdrpenguin04

Ugh, I see what they're going for, but it still feels unfortunate to overlap prelude names.

The full path should be ::core::option::Option to fully distinguish the crate from a local module named core.

cuviper avatar Apr 18 '22 21:04 cuviper