@@ -23,26 +23,57 @@ use rustc_plugin::Registry;
23
23
use rustc:: hir;
24
24
use syntax:: attr;
25
25
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
+ }
27
35
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
+ }
29
46
30
- impl LintPass for Pass {
31
- fn get_lints ( & self ) -> LintArray {
32
- lint_array ! ( CRATE_NOT_OKAY )
33
47
}
34
48
}
35
49
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"
43
72
}
44
73
45
74
#[ plugin_registrar]
46
75
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 ) ;
48
79
}
0 commit comments