Skip to content

Derive macros are not hygienic enough #266

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

Closed
ADD-SP opened this issue Apr 14, 2025 · 0 comments · Fixed by #265
Closed

Derive macros are not hygienic enough #266

ADD-SP opened this issue Apr 14, 2025 · 0 comments · Fixed by #265

Comments

@ADD-SP
Copy link
Contributor

ADD-SP commented Apr 14, 2025

The following code is unable to compile, this issue was found while testing my own project.

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.

// empty module has nothing and be used to redefine symbols
mod empty {}

// redefine the prelude `::std`
use empty as std;

// redefine the dependency `::prometheus_client`
use empty as prometheus_client;

// redefine the prelude `::core::result::Result`.
type Result = ();

enum TResult {
    Ok,
    Err,
}

// redefine the prelude `::core::result::Result::Ok/Err`.
use TResult::Ok;
use TResult::Err;

#[derive(Debug, Clone, PartialEq, Eq, Hash, ::prometheus_client::encoding::EncodeLabelSet)]
struct LableSet {
    a: String,
    b: LabelEnum,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, ::prometheus_client::encoding::EncodeLabelValue)]
enum LabelEnum {
    A,
    B,
}

fn main() {}
@ADD-SP ADD-SP changed the title Derive macro is not hygienic enough Derive macros are not hygienic enough Apr 14, 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 a pull request may close this issue.

1 participant