Skip to content

Commit ae47248

Browse files
committed
Auto merge of #39145 - nrc:opt-cfg-mod, r=@jseyfried
Add an option to the parser so cfg'ed out modules can still be parsed r? @jseyfried cc @dtolnay, @erickt it would be great if we could get this picked up into Syntex asap - it fixes a pretty nasty bug in Rustfmt.
2 parents 0ba6038 + 44180c8 commit ae47248

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/libsyntax/parse/parser.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ pub struct Parser<'a> {
183183
pub expected_tokens: Vec<TokenType>,
184184
pub tts: Vec<(TokenTree, usize)>,
185185
pub desugar_doc_comments: bool,
186+
/// Whether we should configure out of line modules as we parse.
187+
pub cfg_mods: bool,
186188
}
187189

188190
#[derive(PartialEq, Eq, Clone)]
@@ -273,6 +275,7 @@ impl<'a> Parser<'a> {
273275
expected_tokens: Vec::new(),
274276
tts: if tt.len() > 0 { vec![(tt, 0)] } else { Vec::new() },
275277
desugar_doc_comments: desugar_doc_comments,
278+
cfg_mods: true,
276279
};
277280

278281
let tok = parser.next_tok();
@@ -5210,7 +5213,7 @@ impl<'a> Parser<'a> {
52105213
features: None, // don't perform gated feature checking
52115214
};
52125215
let outer_attrs = strip_unconfigured.process_cfg_attrs(outer_attrs.to_owned());
5213-
(strip_unconfigured.in_cfg(&outer_attrs), outer_attrs)
5216+
(!self.cfg_mods || strip_unconfigured.in_cfg(&outer_attrs), outer_attrs)
52145217
};
52155218

52165219
let id_span = self.span;
@@ -5396,6 +5399,7 @@ impl<'a> Parser<'a> {
53965399

53975400
let mut p0 =
53985401
new_sub_parser_from_file(self.sess, &path, directory_ownership, Some(name), id_sp);
5402+
p0.cfg_mods = self.cfg_mods;
53995403
let mod_inner_lo = p0.span.lo;
54005404
let mod_attrs = p0.parse_inner_attributes()?;
54015405
let m0 = p0.parse_mod_items(&token::Eof, mod_inner_lo)?;

0 commit comments

Comments
 (0)