From b08043ee69d45ebe048d1a3d48bce8c52ccffc60 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/librustc_passes/ast_validation.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 341c9d820e651..2d7aab1b4557f 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -19,6 +19,7 @@ use rustc::lint; use rustc::session::Session; use syntax::ast::*; +use syntax::attr; use syntax::parse::token::{self, keywords}; use syntax::visit::{self, Visitor}; use syntax_pos::Span; @@ -168,6 +169,10 @@ impl<'a> Visitor for AstValidator<'a> { } } } + ItemKind::Mod(_) => { + // Ensure that `path` attributes on modules are recorded as used (c.f. #35584). + attr::first_attr_value_str_by_name(&item.attrs, "path"); + } _ => {} } From 4943e96a0c62338a15ad4cc8533d3d4e78ace5b0 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; +}