Skip to content

Commit

Permalink
Rollup merge of rust-lang#35617 - jseyfried:fix_unused_cfg_attr_path,…
Browse files Browse the repository at this point in the history
… r=eddyb

Fix incorrect unused import warnings on `cfg_attr`ed `path` attributes

Fixes rust-lang#35584.
r? @eddyb
  • Loading branch information
Manishearth authored Aug 13, 2016
2 parents d92f339 + 9794fe5 commit fdce693
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/libsyntax/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ impl<'a> StripUnconfigured<'a> {
};

if attr::cfg_matches(self.config, &cfg, self.sess, self.features) {
self.process_cfg_attr(respan(mi.span, ast::Attribute_ {
let inner_attr = respan(mi.span, ast::Attribute_ {
id: attr::mk_attr_id(),
style: attr.node.style,
value: mi.clone(),
is_sugared_doc: false,
}))
});
if attr::is_used(&attr) {
attr::mark_used(&inner_attr);
}
self.process_cfg_attr(inner_attr)
} else {
None
}
Expand Down
16 changes: 14 additions & 2 deletions src/test/compile-fail/cfg_attr_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,17 @@
// 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
#![feature(rustc_attrs)]
#![allow(dead_code)]
#![deny(unused_attributes)] // c.f #35584

mod auxiliary {
#[cfg_attr(any(), path = "nonexistent_file.rs")] pub mod namespaced_enums;
#[cfg_attr(all(), path = "namespaced_enums.rs")] pub mod nonexistent_file;
}

#[rustc_error]
fn main() { //~ ERROR compilation successful
let _ = auxiliary::namespaced_enums::Foo::A;
let _ = auxiliary::nonexistent_file::Foo::A;
}

0 comments on commit fdce693

Please sign in to comment.