Skip to content

fix(derive-encode): expand prelude symbols to absolute paths #265

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

Merged

Conversation

ADD-SP
Copy link
Contributor

@ADD-SP ADD-SP commented Apr 14, 2025

Summary

This PR expands prelude symbols like Ok() and prometheus_client to absolute paths to make it more hygienic.

Full changes

  1. Add new dev-dependency trybuild to test procedure macro.
  2. Expand the following symbols to absolute paths
    1. prometheus_client::encoding::* -> ::prometheus_client::encoding::*
    2. std::result::Result -> ::core::result::Result
    3. std::fmt::Error -> ::core::fmt::Error
    4. Ok(()) -> ::core::result::Result::Ok(())
    5. std::fmt::Write -> ::core::fmt::Write

References

According to proc-macro-workshop:

Generally all macros (procedural as well as macro_rules) designed to be used
by other people should refer to every single thing in their expanded code
through an absolute path, such as std::result::Result.

Issues

Closes #266

According to [1]:
> Generally all macros (procedural as well as macro_rules) designed to be used
> by other people should refer to every single thing in their expanded code
> through an absolute path, such as std::result::Result.

[1]: https://github.com/dtolnay/proc-macro-workshop/blob/3b6bcd2c3ad1c1946e6fbcc9be25d3890876087d/builder/tests/09-redefined-prelude-types.rs#L13C1-L15C58

Signed-off-by: ADD-SP <[email protected]>
@ADD-SP ADD-SP force-pushed the add_sp/fix-handle-redefined-prelude-symbols branch from 3793a24 to 02af0da Compare April 14, 2025 11:22
Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done. Thanks!

@mxinden mxinden merged commit adc7c4e into prometheus:master Apr 16, 2025
10 checks passed
@ADD-SP ADD-SP deleted the add_sp/fix-handle-redefined-prelude-symbols branch April 16, 2025 23:16
ADD-SP added a commit to ADD-SP/client_rust that referenced this pull request Apr 17, 2025
ADD-SP added a commit to ADD-SP/client_rust that referenced this pull request Apr 17, 2025
ADD-SP added a commit to ADD-SP/client_rust that referenced this pull request Apr 19, 2025
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 this pull request may close these issues.

Derive macros are not hygienic enough
2 participants