From 9b9aae83789aa9b5098c10be0e05338577bc1526 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Fri, 12 Aug 2016 08:15:40 +0000 Subject: [PATCH 1/2] Allow attributes to be marked used before `cfg` proccessing. --- src/libsyntax/config.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index a825cf866a878..5e3ee89f5643b 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -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 } From 9794fe5764adec338b1c38f19055c8cc639b7e04 Mon Sep 17 00:00:00 2001 From: Jeffrey Seyfried Date: Fri, 12 Aug 2016 08:30:48 +0000 Subject: [PATCH 2/2] Add regression test. --- src/test/compile-fail/cfg_attr_path.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/test/compile-fail/cfg_attr_path.rs b/src/test/compile-fail/cfg_attr_path.rs index 502768cc44e41..7d799850a651e 100644 --- a/src/test/compile-fail/cfg_attr_path.rs +++ b/src/test/compile-fail/cfg_attr_path.rs @@ -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; +}