-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Support #[macro_use]
on extern crate
#1743
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
Conversation
0f998aa
to
dfa758f
Compare
|
||
self.update(module_id, Some(import_id), ¯os); | ||
} | ||
} |
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.
This I think goes into a slightly wrong direction at the moment.
The problem is that there are essentially two modes for resolving macros.
In the new mode, macros are items, and are imported by paths.
In the old mode, there's a mutable set of currently defined macros in the parser, and foo!()
invocation is looked up in the map.
This code uses the new model of scopes, but macro_use / macro_export are fundamentally tied to the old mode.
Instead, I think we should do the following:
- Add
exported_macros: FxHashSet<Name, MacroDef>
toCrateDefMap
(note, this should be crate level) - Populate this set when we collect the crate
- When we encounter an
#[macro_use] extern crate
, add the cratesexported_macros
toglobal_macro_scope
inDeCollector
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.
Also, let's put a mark into this if
and the corresponding test
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.
And I think we need some special handing for core
and std
crates, which are macro_use
even without an explicit extern crate
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.
Fixed.
For the prelude, it is now handled in name resolving. Would it be better to also search exported_macros
when resolving names (here) instead of early-import?
When resolving names, if there is no So I have moved codes for macro importing into |
Perfect, thanks @uHOOCCOOHu bors r+ |
Build succeeded |
1771: Further tweak for macro_use on extern crate r=matklad a=uHOOCCOOHu Some more tweaks to #1743 to behave more like `rustc` 1. Hoist macros from `#[macro_use] extern crate`, so that they can be used before `extern crate`. 2. Implicit `#[macro_use]` for `prelude` if exists Co-authored-by: uHOOCCOOHu <hooccooh1896@gmail.com>
Unfortunately, #1688 is still an issue. My guess is wrong :(