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
|
@ -562,14 +562,9 @@ fn is_cfg(attr: &Attribute) -> bool {
|
||||||
|
|
||||||
/// Process the potential `cfg` attributes on a module.
|
/// Process the potential `cfg` attributes on a module.
|
||||||
/// Also determine if the module should be included in this configuration.
|
/// Also determine if the module should be included in this configuration.
|
||||||
pub fn process_configure_mod(
|
pub fn process_configure_mod(sess: &ParseSess, cfg_mods: bool, attrs: &mut Vec<Attribute>) -> bool {
|
||||||
sess: &ParseSess,
|
|
||||||
cfg_mods: bool,
|
|
||||||
attrs: &[Attribute],
|
|
||||||
) -> (bool, Vec<Attribute>) {
|
|
||||||
// Don't perform gated feature checking.
|
// Don't perform gated feature checking.
|
||||||
let mut strip_unconfigured = StripUnconfigured { sess, features: None };
|
let mut strip_unconfigured = StripUnconfigured { sess, features: None };
|
||||||
let mut attrs = attrs.to_owned();
|
strip_unconfigured.process_cfg_attrs(attrs);
|
||||||
strip_unconfigured.process_cfg_attrs(&mut attrs);
|
!cfg_mods || strip_unconfigured.in_cfg(&attrs)
|
||||||
(!cfg_mods || strip_unconfigured.in_cfg(&attrs), attrs)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,7 +168,7 @@ impl<'a> Parser<'a> {
|
||||||
self.parse_item_impl(unsafety, defaultness)?
|
self.parse_item_impl(unsafety, defaultness)?
|
||||||
} else if self.eat_keyword(kw::Mod) {
|
} else if self.eat_keyword(kw::Mod) {
|
||||||
// MODULE ITEM
|
// MODULE ITEM
|
||||||
self.parse_item_mod(&attrs[..])?
|
self.parse_item_mod(attrs)?
|
||||||
} else if self.eat_keyword(kw::Type) {
|
} else if self.eat_keyword(kw::Type) {
|
||||||
// TYPE ITEM
|
// TYPE ITEM
|
||||||
let (ident, ty, generics) = self.parse_type_alias()?;
|
let (ident, ty, generics) = self.parse_type_alias()?;
|
||||||
|
|
|
@ -40,36 +40,34 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses a `mod <foo> { ... }` or `mod <foo>;` item.
|
/// Parses a `mod <foo> { ... }` or `mod <foo>;` item.
|
||||||
pub(super) fn parse_item_mod(&mut self, outer_attrs: &[Attribute]) -> PResult<'a, ItemInfo> {
|
pub(super) fn parse_item_mod(&mut self, attrs: &mut Vec<Attribute>) -> PResult<'a, ItemInfo> {
|
||||||
let (in_cfg, outer_attrs) =
|
let in_cfg = crate::config::process_configure_mod(self.sess, self.cfg_mods, attrs);
|
||||||
crate::config::process_configure_mod(self.sess, self.cfg_mods, outer_attrs);
|
|
||||||
|
|
||||||
let id_span = self.token.span;
|
let id_span = self.token.span;
|
||||||
let id = self.parse_ident()?;
|
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 {
|
if in_cfg && self.recurse_into_file_modules {
|
||||||
// This mod is in an external file. Let's go get it!
|
// This mod is in an external file. Let's go get it!
|
||||||
let ModulePathSuccess { path, directory_ownership } =
|
let ModulePathSuccess { path, directory_ownership } =
|
||||||
self.submod_path(id, &outer_attrs, id_span)?;
|
self.submod_path(id, &attrs, id_span)?;
|
||||||
let (module, attrs) =
|
self.eval_src_mod(path, directory_ownership, id.to_string(), id_span)?
|
||||||
self.eval_src_mod(path, directory_ownership, id.to_string(), id_span)?;
|
|
||||||
Ok((id, ItemKind::Mod(module), Some(attrs)))
|
|
||||||
} else {
|
} else {
|
||||||
let placeholder = ast::Mod { inner: DUMMY_SP, items: Vec::new(), inline: false };
|
(ast::Mod { inner: DUMMY_SP, items: Vec::new(), inline: false }, Vec::new())
|
||||||
Ok((id, ItemKind::Mod(placeholder), None))
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let old_directory = self.directory.clone();
|
let old_directory = self.directory.clone();
|
||||||
self.push_directory(id, &outer_attrs);
|
self.push_directory(id, &attrs);
|
||||||
|
|
||||||
self.expect(&token::OpenDelim(token::Brace))?;
|
self.expect(&token::OpenDelim(token::Brace))?;
|
||||||
let mod_inner_lo = self.token.span;
|
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)?;
|
let module = self.parse_mod_items(&token::CloseDelim(token::Brace), mod_inner_lo)?;
|
||||||
|
|
||||||
self.directory = old_directory;
|
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.
|
/// Given a termination token, parses all of the items in a module.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue