Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macros are unhygenic #51

Closed
rdrpenguin04 opened this issue Apr 16, 2022 · 1 comment · Fixed by #57
Closed

Macros are unhygenic #51

rdrpenguin04 opened this issue Apr 16, 2022 · 1 comment · Fixed by #57

Comments

@rdrpenguin04
Copy link

rdrpenguin04 commented Apr 16, 2022

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.

@cuviper
Copy link
Member

cuviper commented Apr 18, 2022

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.

bors bot added a commit that referenced this issue Jul 5, 2023
57: Emit full paths for `Option` and `Result` r=cuviper a=cuviper

This drops any assumption about having `Option` and `Result` through the
normal prelude. This also fixes #51 hygiene, as weird local types by the
same name won't affect the derived code.


Co-authored-by: Josh Stone <cuviper@gmail.com>
@bors bors bot closed this as completed in b0186e5 Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants