Visibilities of "private" items from macros 1.2 #50130
Labels
A-macros-2.0
Area: Declarative macros 2.0 (#39412)
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Procedural macros generate tokens, but sometimes the information is kept not in tokens, but rather in the lack of them.
Look at the
struct S
in the macro below, it doesn't have apub
annotation, so it's private and "private" is desugared intopub(self)
whereself
is the current module, but "current module" depends on the location from which we resolveself
.If
self
is resolved from the macro def-site, then the current module ism
, ifself
is resolved from the macro call-site, then the current module is crate root.The question is what kind of
self
is implicitly generated for private items from macros.Unfortunately, as far as I know, the only viable answer right now is
self
is the module in which the item will end up after all the macro expansions (i.e. "transitive call-site").There are some alternatives potentially (#40847 (comment)), but if
self
is resolved from def site, then we'll get "visibilities can only be restricted to ancestor modules" errors and also conservative type privacy errors on every use of the generated struct.These issues are probably resolvable, but they require nontrivial amount of design and implementation work and we can't delay stabilization of items-without-pub defined by macros until then.
The text was updated successfully, but these errors were encountered: