Skip to content
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

Do not re-export macros that are already at the crate root #88335

Closed
wants to merge 19 commits into from

Conversation

cjgillot
Copy link
Contributor

Follow-up to #88019

Exported macro_rules were unconditionally reexported at the crate root. In the case of macro_rules that were already at the root, both the macro itself and its reexport appear with the same name in the same scope, which confuses the resolver for downstream crates.

This PR skips creating a re-export when the macro was already at the crate root.
r? @petrochenkov

@cjgillot cjgillot added the S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. label Aug 25, 2021
@rust-highfive
Copy link
Collaborator

Some changes occurred in src/tools/clippy.

cc @rust-lang/clippy

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 25, 2021
@rust-log-analyzer

This comment has been minimized.

MacroNS,
(res, vis, span, expansion, IsMacroExport),
);
}
Copy link
Contributor

@petrochenkov petrochenkov Aug 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect, all macro_export-ed macro_rules should be "planted" into the root module (this is what define does), without that they will remain non-modularized even if the macro_rules itself is in the root module.

decoder.rs must also filter away macro_rules items in each_child_of_item or at some level above, there's no way around that - macro_rules items should not appear in the list of module childern from name resolution point of view.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other users of each_child_of_item need to be audited on whether they want to see macro_rules items as children, but fn build_reduced_graph_external is the one use that certainly should filter them away.

Copy link
Contributor

@petrochenkov petrochenkov Aug 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test case for filtering in build_reduced_graph_external:

macro m() {}
macro_rules! m { () => () }

If macro_rules items are not skipped, then this will cause an error during decoding.

If macro_rules items are not skipped, then paths like other_crate::some_mod::some_exported_macro_rules will suddenly start working as well.

@@ -1392,7 +1392,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
// FIXME: Implement actual cross-crate hygiene.
let is_good_import =
binding.is_import() && !binding.is_ambiguity() && !ident.span.from_expansion();
if is_good_import || binding.is_macro_def() {
if is_good_import || binding.is_macro_export() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit of logic is correct - we don't need to represent any macros as reexports, except for the "root reexports" of macro_exported macro_rules.

@petrochenkov petrochenkov removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 25, 2021
@cjgillot cjgillot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 25, 2021
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-10 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
   Compiling parking_lot v0.11.1
   Compiling cstr v0.2.8
   Compiling rand_core v0.5.1
   Compiling regex-automata v0.1.10
error[E0428]: the name `extern_item` is defined multiple times
  --> /cargo/registry/src/github.com-1ecc6299db9ec823/psm-0.1.11/src/lib.rs:27:1
15 | macro_rules! extern_item {
15 | macro_rules! extern_item {
   | ------------------------ previous definition of the macro `extern_item` here
27 | macro_rules! extern_item {
27 | macro_rules! extern_item {
   | ^^^^^^^^^^^^^^^^^^^^^^^^ `extern_item` redefined here
   |
   = note: `extern_item` must be defined only once in the macro namespace of this crate
   Compiling regex v1.4.6
   Compiling rand_chacha v0.3.0
For more information about this error, try `rustc --explain E0428`.
error: could not compile `stacker` due to previous error

@cjgillot cjgillot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 25, 2021
@bors
Copy link
Contributor

bors commented Aug 27, 2021

☔ The latest upstream changes (presumably #88371) made this pull request unmergeable. Please resolve the merge conflicts.

@petrochenkov
Copy link
Contributor

#88019 has been merged, unblocking.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. labels Aug 28, 2021
@JohnCSimon
Copy link
Member

Triage: Merge conflicts

@JohnCSimon
Copy link
Member

Ping @cjgillot

#88019 has been merged, unblocking.

@petrochenkov
Copy link
Contributor

I'm going to close this in favor of #91795.

@cjgillot cjgillot deleted the no-macro-reexport branch December 11, 2021 15:42
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Feb 24, 2022
resolve/metadata: Stop encoding macros as reexports

Supersedes rust-lang#88335.
r? `@cjgillot`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants