expand: Align some code with the PR fixing inner attributes on out-of-line modules
This commit is contained in:
parent
da3419e18c
commit
29a9ef2818
1 changed files with 13 additions and 6 deletions
|
@ -1280,8 +1280,12 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
|
||||||
}
|
}
|
||||||
ast::ItemKind::Mod(_, ref mut mod_kind) if ident != Ident::invalid() => {
|
ast::ItemKind::Mod(_, ref mut mod_kind) if ident != Ident::invalid() => {
|
||||||
let (file_path, dir_path, dir_ownership) = match mod_kind {
|
let (file_path, dir_path, dir_ownership) = match mod_kind {
|
||||||
ModKind::Loaded(_, Inline::Yes, _) => {
|
ModKind::Loaded(_, inline, _) => {
|
||||||
// Inline `mod foo { ... }`, but we still need to push directories.
|
// Inline `mod foo { ... }`, but we still need to push directories.
|
||||||
|
assert!(
|
||||||
|
*inline == Inline::Yes,
|
||||||
|
"`mod` item is loaded from a file for the second time"
|
||||||
|
);
|
||||||
let (dir_path, dir_ownership) = mod_dir_path(
|
let (dir_path, dir_ownership) = mod_dir_path(
|
||||||
&self.cx.sess,
|
&self.cx.sess,
|
||||||
ident,
|
ident,
|
||||||
|
@ -1292,11 +1296,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
|
||||||
item.attrs = attrs;
|
item.attrs = attrs;
|
||||||
(None, dir_path, dir_ownership)
|
(None, dir_path, dir_ownership)
|
||||||
}
|
}
|
||||||
ModKind::Loaded(_, Inline::No, _) => {
|
|
||||||
panic!("`mod` item is loaded from a file for the second time")
|
|
||||||
}
|
|
||||||
ModKind::Unloaded => {
|
ModKind::Unloaded => {
|
||||||
// We have an outline `mod foo;` so we need to parse the file.
|
// We have an outline `mod foo;` so we need to parse the file.
|
||||||
|
let old_attrs_len = attrs.len();
|
||||||
let ParsedExternalMod {
|
let ParsedExternalMod {
|
||||||
mut items,
|
mut items,
|
||||||
inner_span,
|
inner_span,
|
||||||
|
@ -1318,8 +1320,13 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
|
||||||
|
|
||||||
*mod_kind = ModKind::Loaded(items, Inline::No, inner_span);
|
*mod_kind = ModKind::Loaded(items, Inline::No, inner_span);
|
||||||
item.attrs = attrs;
|
item.attrs = attrs;
|
||||||
// File can have inline attributes, e.g., `#![cfg(...)]` & co. => Reconfigure.
|
if item.attrs.len() > old_attrs_len {
|
||||||
|
// If we loaded an out-of-line module and added some inner attributes,
|
||||||
|
// then we need to re-configure it.
|
||||||
|
// FIXME: Attributes also need to be recollected
|
||||||
|
// for resolution and expansion.
|
||||||
item = configure!(self, item);
|
item = configure!(self, item);
|
||||||
|
}
|
||||||
(Some(file_path), dir_path, dir_ownership)
|
(Some(file_path), dir_path, dir_ownership)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue