about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-08-16 06:32:20 -0700
committerGitHub <noreply@github.com>2016-08-16 06:32:20 -0700
commit1de5b7e8c2cc276c0a55c5b9f387185e7d48522e (patch)
treec5e880b3cb98141bce58c4e52be13fe3efbfa48b
parente25542cb02d946959517ebb68e2f7b1318817237 (diff)
parent4943e96a0c62338a15ad4cc8533d3d4e78ace5b0 (diff)
downloadrust-1de5b7e8c2cc276c0a55c5b9f387185e7d48522e.tar.gz
rust-1de5b7e8c2cc276c0a55c5b9f387185e7d48522e.zip
Auto merge of #35617 - jseyfried:fix_unused_cfg_attr_path, r=eddyb
Fix incorrect unused import warnings on `cfg_attr`ed `path` attributes

Fixes #35584.
r? @eddyb
-rw-r--r--src/librustc_passes/ast_validation.rs5
-rw-r--r--src/test/compile-fail/cfg_attr_path.rs16
2 files changed, 19 insertions, 2 deletions
diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs
index 1e8da29ee74..46124d0f973 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");
+            }
             _ => {}
         }
 
diff --git a/src/test/compile-fail/cfg_attr_path.rs b/src/test/compile-fail/cfg_attr_path.rs
index 502768cc44e..7d799850a65 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;
+}