Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upVisibilities of "private" items from macros 1.2 #50130
Comments
petrochenkov
added
the
A-macros-2.0
label
Apr 21, 2018
petrochenkov
referenced this issue
May 1, 2018
Closed
How to determine hygienic context for the "crate root" in absolute-by-default paths #50376
XAMPPRocky
added
C-enhancement
T-compiler
labels
Sep 25, 2018
This comment has been minimized.
This comment has been minimized.
|
Macros 1.2 were stabilized with "implicit private" visibilities behaving as described. |
petrochenkov
closed this
Dec 2, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
petrochenkov commentedApr 21, 2018
Procedural macros generate tokens, but sometimes the information is kept not in tokens, but rather in the lack of them.
Look at the
struct Sin the macro below, it doesn't have apubannotation, so it's private and "private" is desugared intopub(self)whereselfis the current module, but "current module" depends on the location from which we resolveself.If
selfis resolved from the macro def-site, then the current module ism, ifselfis resolved from the macro call-site, then the current module is crate root.The question is what kind of
selfis implicitly generated for private items from macros.Unfortunately, as far as I know, the only viable answer right now is
selfis 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
selfis 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.