Skip to content

Accessing private fields from the def site of a proc macro #46635

Open
@antoyo

Description

@antoyo

Hi.
I'm not sure whether it is a bug or not, that may be an hygiene issue.
But, in the following repository, if you run it with cargo build, you get the following error:

error[E0451]: field `my_field` of struct `MyStruct` is private
  --> src/main.rs:12:5
   |
12 |     pp!(MyStruct);
   |     ^^^^^^^^^^^^^^ field `my_field` is private

However, that does not make sense, because the field is declared in the same module:

struct MyStruct {
    my_field: i32,
}

fn main() {
    pp!(MyStruct); // Error: field `my_field` of struct `MyStruct` is private.
}

This only happens when this feature is enabled.
What makes me think this might be an hygiene issue is that I hard-coded the field name here.
So, if it's a bug, please fix this issue.
Thank you.

Metadata

Metadata

Assignees

Labels

A-decl-macros-2-0Area: Declarative macros 2.0 (#39412)A-hygieneArea: Macro hygieneA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-proc-macrosArea: Procedural macrosC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions