diff options
| author | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-09-14 22:36:42 +0000 |
|---|---|---|
| committer | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-09-15 08:16:18 +0000 |
| commit | b232f6d9fe9ce822aa38cb164e4dce3e4faf5cc4 (patch) | |
| tree | 92c75982e16da9d4b774f200b63fa6037bdedd54 | |
| parent | 5a5736db916ac30ca67945bbf0aee41ced1fcf05 (diff) | |
| download | rust-b232f6d9fe9ce822aa38cb164e4dce3e4faf5cc4.tar.gz rust-b232f6d9fe9ce822aa38cb164e4dce3e4faf5cc4.zip | |
Avoid loading and parsing unconfigured non-inline modules.
| -rw-r--r-- | src/libsyntax/config.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 27 |
2 files changed, 19 insertions, 10 deletions
diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index 3f5b294cc04..abbbbe1e3d1 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -126,7 +126,7 @@ impl<'a> StripUnconfigured<'a> { } // Determine if a node with the given attributes should be included in this configuation. - fn in_cfg(&mut self, attrs: &[ast::Attribute]) -> bool { + pub fn in_cfg(&mut self, attrs: &[ast::Attribute]) -> bool { attrs.iter().all(|attr| { // When not compiling with --test we should not compile the #[test] functions if !self.should_test && is_test_or_bench(attr) { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 6a0e40edded..fd2ae3b4908 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5291,20 +5291,29 @@ impl<'a> Parser<'a> { /// Parse a `mod <foo> { ... }` or `mod <foo>;` item fn parse_item_mod(&mut self, outer_attrs: &[Attribute]) -> PResult<'a, ItemInfo> { - let outer_attrs = ::config::StripUnconfigured { - config: &self.cfg, - sess: self.sess, - should_test: false, // irrelevant - features: None, // don't perform gated feature checking - }.process_cfg_attrs(outer_attrs.to_owned()); + let (in_cfg, outer_attrs) = { + let mut strip_unconfigured = ::config::StripUnconfigured { + config: &self.cfg, + sess: self.sess, + should_test: false, // irrelevant + features: None, // don't perform gated feature checking + }; + let outer_attrs = strip_unconfigured.process_cfg_attrs(outer_attrs.to_owned()); + (strip_unconfigured.in_cfg(&outer_attrs), outer_attrs) + }; let id_span = self.span; let id = self.parse_ident()?; if self.check(&token::Semi) { self.bump(); - // This mod is in an external file. Let's go get it! - let (m, attrs) = self.eval_src_mod(id, &outer_attrs, id_span)?; - Ok((id, m, Some(attrs))) + if in_cfg { + // This mod is in an external file. Let's go get it! + let (m, attrs) = self.eval_src_mod(id, &outer_attrs, id_span)?; + Ok((id, m, Some(attrs))) + } else { + let placeholder = ast::Mod { inner: syntax_pos::DUMMY_SP, items: Vec::new() }; + Ok((id, ItemKind::Mod(placeholder), None)) + } } else { let directory = self.directory.clone(); self.push_directory(id, &outer_attrs); |
