-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support pub
on macro_rules
#78166
Support pub
on macro_rules
#78166
Conversation
r? @varkor (rust_highfive has picked a reviewer for you, use r? to override) |
Impl effort for rust-analyzer would be slightly higher, but still minuscule, and, hey, I'd gave a kingdom for every removal of scoping breaching feature, if I had several spare kingdoms. |
69e46a5
to
8850f51
Compare
pub macro_rules
pub
on macro_rules
Updated with a feature gate and tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me after @Aaron1011's comment has been addressed.
8850f51
to
7d3bb8b
Compare
☔ The latest upstream changes (presumably #78889) made this pull request unmergeable. Please resolve the merge conflicts. Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:
|
TODO: Add a cross-crate test, looks like I forgot to "export" these macros during HIR lowering. |
We discussed this in the @rust-lang/lang meeting today. We're quite enthusiastic about this. We do think, procedurally, this needs at least a minimal spec (even if that spec is as simple as "this behaves the same as Is there any other minor transition on macros that we'd want to key off of this? This is a major user-visible feature. We'll need to document it. |
Also, after this becomes stable, we should ideally have a rustfix-able lint on |
There's a documentation in the top post.
It's indeed pretty simple. (Behaving same as
Minor? Probably not.
This is a major issue. |
@petrochenkov Thank you for the clarification. Making Based on the language used in https://doc.rust-lang.org/reference/macros-by-example.html#scoping-exporting-and-importing , would it be accurate to say that a If so, I'd personally be happy to accept this PR as-is, as long as there's a patch to the reference before we stabilize it. In theory, would it be possible for the 2021 edition to make path-based scoping the default, but provide some backwards-compatible way to ask for textual scoping, and do textual scoping if you write As for the lint, nevermind about rustfix; now that you've clarified what you mean, I think it'll be reasonable to just have a transition lint, once we have something to transition to. |
Yes, |
@petrochenkov OK, in that case, I'm leaving this nominated to re-discuss at next week's meeting. |
I'm of the opinion that we need an RFC before this can be stabilized. This doesn't have to block the PR from landing, so long as the work is feature gated, but I'd like to fit this work into an active project group that can draft up the RFC and shepherd the feature along. I think my ideal end-point would be that we are able to change the behavior so that (This is precisely the work I think would be good to see figured out in the context of a project group with a known charter.) |
Basically this feels like more than a "tweak" of an existing feature, but a major initiative -- one that would be quite welcome! -- to peel off a part of the "macros 2.0" work and make it work universally (specifically, path-based imports). |
The language team discussed this during triage last week. We had a question for @petrochenkov -- how much work would it be to gate the behavior change here on an edition? And, relatedly, would migration tooling to move users over to the new edition (for example, by importing the macros in submodules and switching to pub(crate) over macro_export attributes on modules) be feasible / something you'd be willing to invest time in implementing/mentoring an implementation of? It was generally the feeling that landing the change such that adding a visibility of any kind to a macro switches you to the new system, but a visibility-free macro is in the lexical scoping system (rather than module private) would be pretty confusing and likely not what we'd want. If we are to stabilize this, I believe that the lang team wanted an RFC laying out the plan for moving from lexical scoped macro_rules to the regular scoping of Rust items, including to what extent that would need the edition pieces above. I would be interested in helping to work on this, FWIW. To land this PR a chartered project group would likely be sufficient. There is some discussion on Zulip laying out some more details as well. |
Making this change or similar changes edition-specific should be nearly trivial.
Migration lints are feasible (for all items listed in #78166 (comment)), but they may have higher failure rate than those lints that we prepared for 2018 edition, because the migration is non-trivial in general case. |
To lang team: this PR has lower priority than #79078. |
6893: Move to upstream `macro_rules!` model r=matklad a=jonas-schievink This changes `macro_rules!` from being treated as a macro invocation to being a first-class item. It also disallows using an additional ident argument for regular macros, so `m! ident(...);` now fails to parse. This matches upstream Rust, and makes the code somewhat simpler by removing repeated "is this a `macro_rules!` call" checks. It will also simplify allowing visibilities on macros, which is currently being proposed in rust-lang/rust#78166. Co-authored-by: Jonas Schievink <[email protected]>
Current lang team discussion about this issue - https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/pub.20macro.20rules |
@petrochenkov The intention was to write an RFC to document more-or-less what this PR was proposing to do, not to diverge substantially. The hope was to revise and accept the RFC, and then accept this PR with very little change expected (possibly just appropriate edition handling). |
@joshtriplett |
@petrochenkov we were discussing with @nikomatsakis and @rylev to land this PR with the feature flag included so we can start testing, and working on edition handling, migration, etc. |
My thought is that we should land this PR as a first step-- I think @spastorino plans to rebase. |
Support `pub` on `macro_rules` This rebases and updates `since` version of rust-lang#78166 from `@petrochenkov` r? `@nikomatsakis`
Support `pub` on `macro_rules` This rebases and updates `since` version of rust-lang#78166 from ``@petrochenkov`` r? ``@nikomatsakis``
This PR shows the amount of effort required to implement
which turns out to be... negative?
pub
(orpub(...)
) here makes the macro use regular module scoping (with specified visibility) used by macros 2.0 and all other non-macro items instead of the traditionalmacro_rules
scoping.pub
provides a way to make a macro public without#[macro_export]
, so that#[macro_export]
can be eliminated on the next edition, for example.cc https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Getting.20rid.20of.20.60.23.5Bmacro_export.5D.20macro_rules.60.20on.202021.20edition
Tracking issue - #78855.
(This PR still needs a feature gate and more tests though.)UPD: Feature gate and tests are added.