about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc/lint/mod.rs13
-rw-r--r--src/test/run-pass-fulldeps/auxiliary/lint_for_crate.rs57
-rw-r--r--src/test/run-pass-fulldeps/issue-15778-pass.rs4
3 files changed, 55 insertions, 19 deletions
diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs
index f4abc54ad2e..b2a9859f68a 100644
--- a/src/librustc/lint/mod.rs
+++ b/src/librustc/lint/mod.rs
@@ -97,12 +97,13 @@ macro_rules! declare_lint {
 
 /// Declare a static `LintArray` and return it as an expression.
 #[macro_export]
-macro_rules! lint_array { ($( $lint:expr ),*) => (
-    {
-        static ARRAY: LintArray = &[ $( &$lint ),* ];
-        ARRAY
-    }
-) }
+macro_rules! lint_array {
+    ($( $lint:expr ),*,) => { lint_array!( $( $lint ),* ) };
+    ($( $lint:expr ),*) => {{
+         static ARRAY: LintArray = &[ $( &$lint ),* ];
+         ARRAY
+    }}
+}
 
 pub type LintArray = &'static [&'static &'static Lint];
 
diff --git a/src/test/run-pass-fulldeps/auxiliary/lint_for_crate.rs b/src/test/run-pass-fulldeps/auxiliary/lint_for_crate.rs
index d3f921e0878..878d64c3473 100644
--- a/src/test/run-pass-fulldeps/auxiliary/lint_for_crate.rs
+++ b/src/test/run-pass-fulldeps/auxiliary/lint_for_crate.rs
@@ -23,26 +23,57 @@ use rustc_plugin::Registry;
 use rustc::hir;
 use syntax::attr;
 
-declare_lint!(CRATE_NOT_OKAY, Warn, "crate not marked with #![crate_okay]");
+macro_rules! fake_lint_pass {
+    ($struct:ident, $lints:expr, $($attr:expr),*) => {
+        struct $struct;
+
+        impl LintPass for $struct {
+            fn get_lints(&self) -> LintArray {
+                $lints
+            }
+        }
 
-struct Pass;
+        impl<'a, 'tcx> LateLintPass<'a, 'tcx> for $struct {
+            fn check_crate(&mut self, cx: &LateContext, krate: &hir::Crate) {
+                $(
+                    if !attr::contains_name(&krate.attrs, $attr) {
+                        cx.span_lint(CRATE_NOT_OKAY, krate.span,
+                                     &format!("crate is not marked with #![{}]", $attr));
+                    }
+                )*
+            }
+        }
 
-impl LintPass for Pass {
-    fn get_lints(&self) -> LintArray {
-        lint_array!(CRATE_NOT_OKAY)
     }
 }
 
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
-    fn check_crate(&mut self, cx: &LateContext, krate: &hir::Crate) {
-        if !attr::contains_name(&krate.attrs, "crate_okay") {
-            cx.span_lint(CRATE_NOT_OKAY, krate.span,
-                         "crate is not marked with #![crate_okay]");
-        }
-    }
+declare_lint!(CRATE_NOT_OKAY, Warn, "crate not marked with #![crate_okay]");
+declare_lint!(CRATE_NOT_RED, Warn, "crate not marked with #![crate_red]");
+declare_lint!(CRATE_NOT_BLUE, Warn, "crate not marked with #![crate_blue]");
+declare_lint!(CRATE_NOT_GREY, Warn, "crate not marked with #![crate_grey]");
+declare_lint!(CRATE_NOT_GREEN, Warn, "crate not marked with #![crate_green]");
+
+fake_lint_pass! {
+    PassOkay,
+    lint_array!(CRATE_NOT_OKAY), // Single lint
+    "crate_okay"
+}
+
+fake_lint_pass! {
+    PassRedBlue,
+    lint_array!(CRATE_NOT_RED, CRATE_NOT_BLUE), // Multiple lints
+    "crate_red", "crate_blue"
+}
+
+fake_lint_pass! {
+    PassGreyGreen,
+    lint_array!(CRATE_NOT_GREY, CRATE_NOT_GREEN, ), // Trailing comma
+    "crate_grey", "crate_green"
 }
 
 #[plugin_registrar]
 pub fn plugin_registrar(reg: &mut Registry) {
-    reg.register_late_lint_pass(box Pass);
+    reg.register_late_lint_pass(box PassOkay);
+    reg.register_late_lint_pass(box PassRedBlue);
+    reg.register_late_lint_pass(box PassGreyGreen);
 }
diff --git a/src/test/run-pass-fulldeps/issue-15778-pass.rs b/src/test/run-pass-fulldeps/issue-15778-pass.rs
index a767779687a..25800d40e71 100644
--- a/src/test/run-pass-fulldeps/issue-15778-pass.rs
+++ b/src/test/run-pass-fulldeps/issue-15778-pass.rs
@@ -15,5 +15,9 @@
 #![feature(plugin, custom_attribute)]
 #![plugin(lint_for_crate)]
 #![crate_okay]
+#![crate_blue]
+#![crate_red]
+#![crate_grey]
+#![crate_green]
 
 pub fn main() { }