Skip to content

Commit 4738076

Browse files
authored
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 ```
2 parents d1e5e3a + ba59d42 commit 4738076

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/libsyntax/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl<'a> StripUnconfigured<'a> {
3333
if self.in_cfg(node.attrs()) { Some(node) } else { None }
3434
}
3535

36-
fn process_cfg_attrs<T: HasAttrs>(&mut self, node: T) -> T {
36+
pub fn process_cfg_attrs<T: HasAttrs>(&mut self, node: T) -> T {
3737
node.map_attrs(|attrs| {
3838
attrs.into_iter().filter_map(|attr| self.process_cfg_attr(attr)).collect()
3939
})

src/libsyntax/parse/parser.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -5296,15 +5296,22 @@ impl<'a> Parser<'a> {
52965296

52975297
/// Parse a `mod <foo> { ... }` or `mod <foo>;` item
52985298
fn parse_item_mod(&mut self, outer_attrs: &[Attribute]) -> PResult<'a, ItemInfo> {
5299+
let outer_attrs = ::config::StripUnconfigured {
5300+
config: &self.cfg,
5301+
sess: self.sess,
5302+
should_test: false, // irrelevant
5303+
features: None, // don't perform gated feature checking
5304+
}.process_cfg_attrs(outer_attrs.to_owned());
5305+
52995306
let id_span = self.span;
53005307
let id = self.parse_ident()?;
53015308
if self.check(&token::Semi) {
53025309
self.bump();
53035310
// This mod is in an external file. Let's go get it!
5304-
let (m, attrs) = self.eval_src_mod(id, outer_attrs, id_span)?;
5311+
let (m, attrs) = self.eval_src_mod(id, &outer_attrs, id_span)?;
53055312
Ok((id, m, Some(attrs)))
53065313
} else {
5307-
self.push_mod_path(id, outer_attrs);
5314+
self.push_mod_path(id, &outer_attrs);
53085315
self.expect(&token::OpenDelim(token::Brace))?;
53095316
let mod_inner_lo = self.span.lo;
53105317
let attrs = self.parse_inner_attributes()?;
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#[cfg_attr(all(), path = "nonexistent_file.rs")] mod foo;
12+
//~^ ERROR nonexistent_file.rs

0 commit comments

Comments
 (0)