Skip to content

Commit fdce693

Browse files
authored
Rollup merge of rust-lang#35617 - jseyfried:fix_unused_cfg_attr_path, r=eddyb
Fix incorrect unused import warnings on `cfg_attr`ed `path` attributes Fixes rust-lang#35584. r? @eddyb
2 parents d92f339 + 9794fe5 commit fdce693

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/libsyntax/config.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,16 @@ impl<'a> StripUnconfigured<'a> {
6262
};
6363

6464
if attr::cfg_matches(self.config, &cfg, self.sess, self.features) {
65-
self.process_cfg_attr(respan(mi.span, ast::Attribute_ {
65+
let inner_attr = respan(mi.span, ast::Attribute_ {
6666
id: attr::mk_attr_id(),
6767
style: attr.node.style,
6868
value: mi.clone(),
6969
is_sugared_doc: false,
70-
}))
70+
});
71+
if attr::is_used(&attr) {
72+
attr::mark_used(&inner_attr);
73+
}
74+
self.process_cfg_attr(inner_attr)
7175
} else {
7276
None
7377
}

src/test/compile-fail/cfg_attr_path.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,17 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[cfg_attr(all(), path = "nonexistent_file.rs")] mod foo;
12-
//~^ ERROR nonexistent_file.rs
11+
#![feature(rustc_attrs)]
12+
#![allow(dead_code)]
13+
#![deny(unused_attributes)] // c.f #35584
14+
15+
mod auxiliary {
16+
#[cfg_attr(any(), path = "nonexistent_file.rs")] pub mod namespaced_enums;
17+
#[cfg_attr(all(), path = "namespaced_enums.rs")] pub mod nonexistent_file;
18+
}
19+
20+
#[rustc_error]
21+
fn main() { //~ ERROR compilation successful
22+
let _ = auxiliary::namespaced_enums::Foo::A;
23+
let _ = auxiliary::nonexistent_file::Foo::A;
24+
}

0 commit comments

Comments
 (0)