Skip to content

Commit 4b77463

Browse files
authored
Rollup merge of rust-lang#47458 - mark-i-m:lint_array_comma, r=estebank
Allow a trailing comma in lint_array fix rust-lang#47428
2 parents 83c895a + f81c2de commit 4b77463

File tree

3 files changed

+55
-19
lines changed

3 files changed

+55
-19
lines changed

src/librustc/lint/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,13 @@ macro_rules! declare_lint {
9797

9898
/// Declare a static `LintArray` and return it as an expression.
9999
#[macro_export]
100-
macro_rules! lint_array { ($( $lint:expr ),*) => (
101-
{
102-
static ARRAY: LintArray = &[ $( &$lint ),* ];
103-
ARRAY
104-
}
105-
) }
100+
macro_rules! lint_array {
101+
($( $lint:expr ),*,) => { lint_array!( $( $lint ),* ) };
102+
($( $lint:expr ),*) => {{
103+
static ARRAY: LintArray = &[ $( &$lint ),* ];
104+
ARRAY
105+
}}
106+
}
106107

107108
pub type LintArray = &'static [&'static &'static Lint];
108109

src/test/run-pass-fulldeps/auxiliary/lint_for_crate.rs

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,57 @@ use rustc_plugin::Registry;
2323
use rustc::hir;
2424
use syntax::attr;
2525

26-
declare_lint!(CRATE_NOT_OKAY, Warn, "crate not marked with #![crate_okay]");
26+
macro_rules! fake_lint_pass {
27+
($struct:ident, $lints:expr, $($attr:expr),*) => {
28+
struct $struct;
29+
30+
impl LintPass for $struct {
31+
fn get_lints(&self) -> LintArray {
32+
$lints
33+
}
34+
}
2735

28-
struct Pass;
36+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for $struct {
37+
fn check_crate(&mut self, cx: &LateContext, krate: &hir::Crate) {
38+
$(
39+
if !attr::contains_name(&krate.attrs, $attr) {
40+
cx.span_lint(CRATE_NOT_OKAY, krate.span,
41+
&format!("crate is not marked with #![{}]", $attr));
42+
}
43+
)*
44+
}
45+
}
2946

30-
impl LintPass for Pass {
31-
fn get_lints(&self) -> LintArray {
32-
lint_array!(CRATE_NOT_OKAY)
3347
}
3448
}
3549

36-
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
37-
fn check_crate(&mut self, cx: &LateContext, krate: &hir::Crate) {
38-
if !attr::contains_name(&krate.attrs, "crate_okay") {
39-
cx.span_lint(CRATE_NOT_OKAY, krate.span,
40-
"crate is not marked with #![crate_okay]");
41-
}
42-
}
50+
declare_lint!(CRATE_NOT_OKAY, Warn, "crate not marked with #![crate_okay]");
51+
declare_lint!(CRATE_NOT_RED, Warn, "crate not marked with #![crate_red]");
52+
declare_lint!(CRATE_NOT_BLUE, Warn, "crate not marked with #![crate_blue]");
53+
declare_lint!(CRATE_NOT_GREY, Warn, "crate not marked with #![crate_grey]");
54+
declare_lint!(CRATE_NOT_GREEN, Warn, "crate not marked with #![crate_green]");
55+
56+
fake_lint_pass! {
57+
PassOkay,
58+
lint_array!(CRATE_NOT_OKAY), // Single lint
59+
"crate_okay"
60+
}
61+
62+
fake_lint_pass! {
63+
PassRedBlue,
64+
lint_array!(CRATE_NOT_RED, CRATE_NOT_BLUE), // Multiple lints
65+
"crate_red", "crate_blue"
66+
}
67+
68+
fake_lint_pass! {
69+
PassGreyGreen,
70+
lint_array!(CRATE_NOT_GREY, CRATE_NOT_GREEN, ), // Trailing comma
71+
"crate_grey", "crate_green"
4372
}
4473

4574
#[plugin_registrar]
4675
pub fn plugin_registrar(reg: &mut Registry) {
47-
reg.register_late_lint_pass(box Pass);
76+
reg.register_late_lint_pass(box PassOkay);
77+
reg.register_late_lint_pass(box PassRedBlue);
78+
reg.register_late_lint_pass(box PassGreyGreen);
4879
}

src/test/run-pass-fulldeps/issue-15778-pass.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@
1515
#![feature(plugin, custom_attribute)]
1616
#![plugin(lint_for_crate)]
1717
#![crate_okay]
18+
#![crate_blue]
19+
#![crate_red]
20+
#![crate_grey]
21+
#![crate_green]
1822

1923
pub fn main() { }

0 commit comments

Comments
 (0)