parser_item_mod: avoid cloning outer attributes
This commit is contained in:
parent
73d5970cdc
commit
20ba6875e6
3 changed files with 16 additions and 23 deletions
|
@ -40,36 +40,34 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
/// Parses a `mod <foo> { ... }` or `mod <foo>;` item.
|
||||
pub(super) fn parse_item_mod(&mut self, outer_attrs: &[Attribute]) -> PResult<'a, ItemInfo> {
|
||||
let (in_cfg, outer_attrs) =
|
||||
crate::config::process_configure_mod(self.sess, self.cfg_mods, outer_attrs);
|
||||
pub(super) fn parse_item_mod(&mut self, attrs: &mut Vec<Attribute>) -> PResult<'a, ItemInfo> {
|
||||
let in_cfg = crate::config::process_configure_mod(self.sess, self.cfg_mods, attrs);
|
||||
|
||||
let id_span = self.token.span;
|
||||
let id = self.parse_ident()?;
|
||||
if self.eat(&token::Semi) {
|
||||
let (module, mut inner_attrs) = if self.eat(&token::Semi) {
|
||||
if in_cfg && self.recurse_into_file_modules {
|
||||
// This mod is in an external file. Let's go get it!
|
||||
let ModulePathSuccess { path, directory_ownership } =
|
||||
self.submod_path(id, &outer_attrs, id_span)?;
|
||||
let (module, attrs) =
|
||||
self.eval_src_mod(path, directory_ownership, id.to_string(), id_span)?;
|
||||
Ok((id, ItemKind::Mod(module), Some(attrs)))
|
||||
self.submod_path(id, &attrs, id_span)?;
|
||||
self.eval_src_mod(path, directory_ownership, id.to_string(), id_span)?
|
||||
} else {
|
||||
let placeholder = ast::Mod { inner: DUMMY_SP, items: Vec::new(), inline: false };
|
||||
Ok((id, ItemKind::Mod(placeholder), None))
|
||||
(ast::Mod { inner: DUMMY_SP, items: Vec::new(), inline: false }, Vec::new())
|
||||
}
|
||||
} else {
|
||||
let old_directory = self.directory.clone();
|
||||
self.push_directory(id, &outer_attrs);
|
||||
self.push_directory(id, &attrs);
|
||||
|
||||
self.expect(&token::OpenDelim(token::Brace))?;
|
||||
let mod_inner_lo = self.token.span;
|
||||
let attrs = self.parse_inner_attributes()?;
|
||||
let inner_attrs = self.parse_inner_attributes()?;
|
||||
let module = self.parse_mod_items(&token::CloseDelim(token::Brace), mod_inner_lo)?;
|
||||
|
||||
self.directory = old_directory;
|
||||
Ok((id, ItemKind::Mod(module), Some(attrs)))
|
||||
}
|
||||
(module, inner_attrs)
|
||||
};
|
||||
attrs.append(&mut inner_attrs);
|
||||
Ok((id, ItemKind::Mod(module), None))
|
||||
}
|
||||
|
||||
/// Given a termination token, parses all of the items in a module.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue