@@ -23,26 +23,57 @@ use rustc_plugin::Registry;
2323use rustc:: hir;
2424use 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]
4675pub 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}
0 commit comments