summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-07-06 00:34:51 -0700
committerGitHub <noreply@github.com>2016-07-06 00:34:51 -0700
commit47380768e7debc2ee6b66e491733b89534e80988 (patch)
tree5d8c6f6facd508b34f15539dd1d9e0d18f055adc /src/libsyntax
parentd1e5e3ab43b02817e22a47a9678ee39ad4c6c96d (diff)
parentba59d42f24e68cae82167372d96e065dd94f36bc (diff)
downloadrust-47380768e7debc2ee6b66e491733b89534e80988.tar.gz
rust-47380768e7debc2ee6b66e491733b89534e80988.zip
Auto merge of #34546 - jseyfried:cfg_attr_path, r=nrc
Support `cfg_attr` on `path` attributes

Fixes #25544.
This is technically a [breaking-change]. For example, the following would break:
```rust
mod foo; // Suppose `foo.rs` existed in the appropriate location
```
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/config.rs2
-rw-r--r--src/libsyntax/parse/parser.rs11
2 files changed, 10 insertions, 3 deletions
diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs
index eaf82f5f43d..ff75149f518 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<T: HasAttrs>(&mut self, node: T) -> T {
+    pub fn process_cfg_attrs<T: HasAttrs>(&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 6fa95afd9fb..a06270bb772 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -5296,15 +5296,22 @@ 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 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()?;