diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index 961763c6025fd..36a4568b693be 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -33,7 +33,7 @@ impl<'a> StripUnconfigured<'a> { if self.in_cfg(node.attrs()) { Some(node) } else { None } } - fn process_cfg_attrs(&mut self, node: T) -> T { + pub fn process_cfg_attrs(&mut self, node: T) -> T { node.map_attrs(|attrs| { attrs.into_iter().filter_map(|attr| self.process_cfg_attr(attr)).collect() }) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 813d90103b887..db101e459dbca 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5301,15 +5301,22 @@ impl<'a> Parser<'a> { /// Parse a `mod { ... }` or `mod ;` 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 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)?; + let (m, attrs) = self.eval_src_mod(id, &outer_attrs, id_span)?; Ok((id, m, Some(attrs))) } else { - self.push_mod_path(id, outer_attrs); + self.push_mod_path(id, &outer_attrs); self.expect(&token::OpenDelim(token::Brace))?; let mod_inner_lo = self.span.lo; let attrs = self.parse_inner_attributes()?; diff --git a/src/test/compile-fail/cfg_attr_path.rs b/src/test/compile-fail/cfg_attr_path.rs new file mode 100644 index 0000000000000..502768cc44e41 --- /dev/null +++ b/src/test/compile-fail/cfg_attr_path.rs @@ -0,0 +1,12 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[cfg_attr(all(), path = "nonexistent_file.rs")] mod foo; +//~^ ERROR nonexistent_file.rs