Skip to content

Commit bcc0707

Browse files
committedJul 10, 2018
Auto merge of #52234 - petrochenkov:macuse2, r=<try>
[Experiment] resolve: Modularize crate-local `#[macro_export] macro_rules` Based on #50911, cc #50911 (comment) `#[macro_export] macro_rules` items are collected from the whole crate and are planted into the root module as items, so the external view of the crate is symmetric with its internal view and something like `$crate::my_macro` where `my_macro` is `#[macro_export] macro_rules` works both locally and from other crates.
2 parents e5f6498 + ee16ce1 commit bcc0707

File tree

59 files changed

+461
-322
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+461
-322
lines changed
 

Diff for: ‎src/doc/unstable-book/src/language-features/proc-macro.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ The two new procedural macro kinds are:
1717
* Attribute-like procedural macros which can be applied to any item which built-in attributes can
1818
be applied to, and which can take arguments in their invocation as well.
1919

20-
Additionally, this feature flag implicitly enables the [`use_extern_macros`](language-features/use-extern-macros.html) feature,
21-
which allows macros to be imported like any other item with `use` statements, as compared to
20+
Procedural macros can be imported like any other item with `use` statements, as compared to
2221
applying `#[macro_use]` to an `extern crate` declaration. It is important to note that procedural macros may
2322
**only** be imported in this manner, and will throw an error otherwise.
2423

Diff for: ‎src/librustc_resolve/build_reduced_graph.rs

+17-10
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ impl<'a> ToNameBinding<'a> for (Module<'a>, ty::Visibility, Span, Mark) {
5252
vis: self.1,
5353
span: self.2,
5454
expansion: self.3,
55+
is_macro_export: false,
5556
})
5657
}
5758
}
@@ -63,6 +64,19 @@ impl<'a> ToNameBinding<'a> for (Def, ty::Visibility, Span, Mark) {
6364
vis: self.1,
6465
span: self.2,
6566
expansion: self.3,
67+
is_macro_export: false,
68+
})
69+
}
70+
}
71+
72+
impl<'a> ToNameBinding<'a> for (Def, ty::Visibility, Span, Mark, bool) {
73+
fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> &'a NameBinding<'a> {
74+
arenas.alloc_name_binding(NameBinding {
75+
kind: NameBindingKind::Def(self.0),
76+
vis: self.1,
77+
span: self.2,
78+
expansion: self.3,
79+
is_macro_export: self.4,
6680
})
6781
}
6882
}
@@ -641,19 +655,12 @@ impl<'a> Resolver<'a> {
641655
-> bool {
642656
let allow_shadowing = expansion == Mark::root();
643657
let legacy_imports = self.legacy_macro_imports(&item.attrs);
644-
let mut used = legacy_imports != LegacyMacroImports::default();
658+
let used = legacy_imports != LegacyMacroImports::default();
645659

646660
// `#[macro_use]` is only allowed at the crate root.
647661
if self.current_module.parent.is_some() && used {
648662
span_err!(self.session, item.span, E0468,
649663
"an `extern crate` loading macros must be at the crate root");
650-
} else if !self.use_extern_macros && !used &&
651-
self.cstore.dep_kind_untracked(module.def_id().unwrap().krate)
652-
.macros_only() {
653-
let msg = "proc macro crates and `#[no_link]` crates have no effect without \
654-
`#[macro_use]`";
655-
self.session.span_warn(item.span, msg);
656-
used = true; // Avoid the normal unused extern crate warning
657664
}
658665

659666
let (graph_root, arenas) = (self.graph_root, self.arenas);
@@ -681,8 +688,7 @@ impl<'a> Resolver<'a> {
681688
} else {
682689
for (name, span) in legacy_imports.imports {
683690
let ident = Ident::with_empty_ctxt(name);
684-
let result = self.resolve_ident_in_module(module, ident, MacroNS,
685-
false, false, span);
691+
let result = self.resolve_ident_in_module(module, ident, MacroNS, false, span);
686692
if let Ok(binding) = result {
687693
let directive = macro_use_directive(span);
688694
self.potentially_unused_imports.push(directive);
@@ -750,6 +756,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
750756
fn visit_invoc(&mut self, id: ast::NodeId) -> &'b InvocationData<'b> {
751757
let mark = id.placeholder_to_mark();
752758
self.resolver.current_module.unresolved_invocations.borrow_mut().insert(mark);
759+
self.resolver.unresolved_invocations_macro_export.insert(mark);
753760
let invocation = self.resolver.invocations[&mark];
754761
invocation.module.set(self.resolver.current_module);
755762
invocation.legacy_scope.set(self.legacy_scope);

0 commit comments

Comments
 (0)