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 upSupport `#[macro_use]` on macro-expanded crates #34032
Conversation
rust-highfive
assigned
nrc
Jun 2, 2016
This comment has been minimized.
This comment has been minimized.
|
cc @durka |
jseyfried
force-pushed the
jseyfried:load_macros_in_expansion
branch
from
1b05450
to
38166c8
Jun 3, 2016
LeoTestard
reviewed
Jun 4, 2016
| @@ -925,4 +940,8 @@ impl SyntaxEnv { | |||
| let last_chain_index = self.chain.len() - 1; | |||
| &mut self.chain[last_chain_index].info | |||
| } | |||
|
|
|||
| pub fn is_crate_root(&mut self) -> bool { | |||
| self.chain.len() == 2 | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
LeoTestard
reviewed
Jun 4, 2016
| for def in fld.cx.loader.load_crate(&it, allows_macros) { | ||
| fld.cx.insert_macro(def); | ||
| } | ||
| SmallVector::one(Annotatable::Item(it)) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
jseyfried
Jun 5, 2016
Author
Contributor
Before this PR, new_attrs wasn't attached back (so the expanded decorator attributes weren't removed) when folding modules, trait items, and impl items, so I don't think it matters much.
That being said, I think the decorator attributes should always be removed since macro expansion should be idempotent, so I added a commit that always reattaches new_attrs.
LeoTestard
reviewed
Jun 4, 2016
| @@ -546,6 +557,7 @@ pub struct ExtCtxt<'a> { | |||
| pub ecfg: expand::ExpansionConfig<'a>, | |||
| pub crate_root: Option<&'static str>, | |||
| pub feature_gated_cfgs: &'a mut Vec<GatedCfgAttr>, | |||
| pub loader: &'a mut MacroLoader, | |||
This comment has been minimized.
This comment has been minimized.
LeoTestard
Jun 4, 2016
Contributor
It's a sad thing that we have to use a trait and a trait object just for tests. Is there no other way? Can't we just create a dummy macro_import::MacroLoader?
This comment has been minimized.
This comment has been minimized.
jseyfried
Jun 5, 2016
Author
Contributor
My main reason for using a trait object is that macro_import::MacroLoader is defined and implemented in librustc_metadata, so libsyntax can't use it directly.
This comment has been minimized.
This comment has been minimized.
|
(Otherwise: |
jseyfried
force-pushed the
jseyfried:load_macros_in_expansion
branch
from
f953a79
to
acbff87
Jun 5, 2016
This comment has been minimized.
This comment has been minimized.
|
@bors: r+ |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
|
jseyfried
added some commits
Jun 2, 2016
jseyfried
force-pushed the
jseyfried:load_macros_in_expansion
branch
from
acbff87
to
dbf0326
Jun 9, 2016
This comment has been minimized.
This comment has been minimized.
|
Rebased. @bors r=nrc |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Jun 9, 2016
This comment has been minimized.
This comment has been minimized.
bors
merged commit dbf0326
into
rust-lang:master
Jun 9, 2016
This comment has been minimized.
This comment has been minimized.
alexcrichton
added
the
relnotes
label
Jun 10, 2016
This comment has been minimized.
This comment has been minimized.
|
Added |
jseyfried commentedJun 2, 2016
•
edited
This PR loads macros from
#[macro_use]crates during expansion so that#[macro_use]crates work (fixes #33936, fixes #28071), andmacros imported from crates have the same scope as macros imported from modules.(EDIT: reverted in #34239)
This is a [breaking-change]. For example, this will break:
Also, this will break:r? @nrc