Skip to content

Derive macros are not hygienic enough #266

@ADD-SP

Description

@ADD-SP

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() {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions