-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
decl_macro can call pub fn methods of private types. #155631
Copy link
Copy link
Open
Labels
A-decl-macros-2-0Area: Declarative macros 2.0 (#39412)Area: Declarative macros 2.0 (#39412)A-hygieneArea: Macro hygieneArea: Macro hygieneA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-method-lookupArea: Method lookup (typeck, post `rustc_resolve`, not to be confused with `A-resolve`)Area: Method lookup (typeck, post `rustc_resolve`, not to be confused with `A-resolve`)A-visibilityArea: Visibility / privacyArea: Visibility / privacyC-bugCategory: This is a bug.Category: This is a bug.F-decl_macro`#![feature(decl_macro)]``#![feature(decl_macro)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Metadata
Metadata
Assignees
Labels
A-decl-macros-2-0Area: Declarative macros 2.0 (#39412)Area: Declarative macros 2.0 (#39412)A-hygieneArea: Macro hygieneArea: Macro hygieneA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-method-lookupArea: Method lookup (typeck, post `rustc_resolve`, not to be confused with `A-resolve`)Area: Method lookup (typeck, post `rustc_resolve`, not to be confused with `A-resolve`)A-visibilityArea: Visibility / privacyArea: Visibility / privacyC-bugCategory: This is a bug.Category: This is a bug.F-decl_macro`#![feature(decl_macro)]``#![feature(decl_macro)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language team
Type
Fields
Give feedbackNo fields configured for issues without a type.
I tried this code:
The
methodis apub fn. However, it is implemented on a private type. Therefore, it should not be callable from outside the module. So, this code shouldn't compile. Instead, this code compiles without errors.Changing
pub fn methodtofn methodcauses the following error, as expected:This behavior also seems to apply to built-in macros. See #155598 (comment)
Meta
Reproducible on the playground with
1.97.0-nightly (2026-04-20 66da6cae1a6f12e95854)