From: Nick Cameron Date: Wed, 18 Jan 2017 00:13:36 +0000 (+1300) Subject: Add an option to the parser so cfg'ed out modules can still be parsed X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=44180c8f2b1f12927c00fd5659a4dc5c04436a9d;p=rust.git Add an option to the parser so cfg'ed out modules can still be parsed --- diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 5dd772041e2..766e0512bdc 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -183,6 +183,8 @@ pub struct Parser<'a> { pub expected_tokens: Vec, pub tts: Vec<(TokenTree, usize)>, pub desugar_doc_comments: bool, + /// Whether we should configure out of line modules as we parse. + pub cfg_mods: bool, } #[derive(PartialEq, Eq, Clone)] @@ -273,6 +275,7 @@ pub fn new(sess: &'a ParseSess, expected_tokens: Vec::new(), tts: if tt.len() > 0 { vec![(tt, 0)] } else { Vec::new() }, desugar_doc_comments: desugar_doc_comments, + cfg_mods: true, }; let tok = parser.next_tok(); @@ -5210,7 +5213,7 @@ fn parse_item_mod(&mut self, outer_attrs: &[Attribute]) -> PResult<'a, ItemInfo> 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) + (!self.cfg_mods || strip_unconfigured.in_cfg(&outer_attrs), outer_attrs) }; let id_span = self.span; @@ -5396,6 +5399,7 @@ fn eval_src_mod(&mut self, let mut p0 = new_sub_parser_from_file(self.sess, &path, directory_ownership, Some(name), id_sp); + p0.cfg_mods = self.cfg_mods; let mod_inner_lo = p0.span.lo; let mod_attrs = p0.parse_inner_attributes()?; let m0 = p0.parse_mod_items(&token::Eof, mod_inner_lo)?;