@@ -491,7 +491,6 @@ fn declare_deprecated(name: &str, path: &Path, reason: &str) -> io::Result<()> {
491
491
492
492
file. seek ( SeekFrom :: End ( 0 ) ) ?;
493
493
494
- let version = crate :: new_lint:: get_stabilization_version ( ) ;
495
494
let deprecation_reason = if reason == DEFAULT_DEPRECATION_REASON {
496
495
"TODO"
497
496
} else {
@@ -508,14 +507,13 @@ fn declare_deprecated(name: &str, path: &Path, reason: &str) -> io::Result<()> {
508
507
///
509
508
/// ### Deprecation reason
510
509
/// {}
511
- #[clippy::version = \" {} \" ]
510
+ #[clippy::version = \" nightly \" ]
512
511
pub {},
513
512
\" {}\"
514
513
}}
515
514
516
515
" ,
517
516
deprecation_reason,
518
- version,
519
517
name,
520
518
reason,
521
519
)
@@ -588,17 +586,26 @@ struct Lint {
588
586
group : String ,
589
587
desc : String ,
590
588
module : String ,
589
+ has_version : bool ,
591
590
declaration_range : Range < usize > ,
592
591
}
593
592
594
593
impl Lint {
595
594
#[ must_use]
596
- fn new ( name : & str , group : & str , desc : & str , module : & str , declaration_range : Range < usize > ) -> Self {
595
+ fn new (
596
+ name : & str ,
597
+ group : & str ,
598
+ desc : & str ,
599
+ module : & str ,
600
+ has_version : bool ,
601
+ declaration_range : Range < usize > ,
602
+ ) -> Self {
597
603
Self {
598
604
name : name. to_lowercase ( ) ,
599
605
group : group. into ( ) ,
600
606
desc : remove_line_splices ( desc) ,
601
607
module : module. into ( ) ,
608
+ has_version,
602
609
declaration_range,
603
610
}
604
611
}
@@ -657,20 +664,36 @@ impl RenamedLint {
657
664
658
665
/// Generates the code for registering a group
659
666
fn gen_lint_group_list < ' a > ( group_name : & str , lints : impl Iterator < Item = & ' a Lint > ) -> String {
660
- let mut details: Vec < _ > = lints. map ( |l| ( & l. module , l. name . to_uppercase ( ) ) ) . collect ( ) ;
661
- details. sort_unstable ( ) ;
667
+ let mut stable_count = 0usize ;
668
+ let mut lints: Vec < _ > = lints
669
+ . inspect ( |l| {
670
+ if l. has_version {
671
+ stable_count += 1 ;
672
+ }
673
+ } )
674
+ . map ( |l| ( !l. has_version , & l. module , l. name . to_uppercase ( ) ) )
675
+ . collect ( ) ;
676
+ lints. sort_unstable ( ) ;
662
677
663
678
let mut output = GENERATED_FILE_COMMENT . to_string ( ) ;
664
-
679
+ let _ = write ! ( output, "{{\n let lints: [LintId; {}] = [\n " , lints. len( ) ) ;
680
+ for ( _, module, name) in & lints {
681
+ let _ = writeln ! ( output, " LintId::of({}::{})," , module, name) ;
682
+ }
683
+ output. push_str ( " ];\n " ) ;
684
+ if stable_count != lints. len ( ) {
685
+ output. push_str ( " let lints = if sess.opts.unstable_features.is_nightly_build() {\n " ) ;
686
+ output. push_str ( " lints.as_slice()\n " ) ;
687
+ output. push_str ( " } else {\n " ) ;
688
+ let _ = writeln ! ( output, " &lints[..{}]" , stable_count) ;
689
+ output. push_str ( " };\n " ) ;
690
+ }
665
691
let _ = writeln ! (
666
692
output,
667
- "store.register_group(true, \" clippy::{0}\" , Some(\" clippy_{0}\" ), vec![ " ,
693
+ " store.register_group(true, \" clippy::{0}\" , Some(\" clippy_{0}\" ), lints.to_vec()); " ,
668
694
group_name
669
695
) ;
670
- for ( module, name) in details {
671
- let _ = writeln ! ( output, " LintId::of({}::{})," , module, name) ;
672
- }
673
- output. push_str ( "])\n " ) ;
696
+ output. push_str ( "}" ) ;
674
697
675
698
output
676
699
}
@@ -858,21 +881,22 @@ fn parse_contents(contents: &str, module: &str, lints: &mut Vec<Lint>) {
858
881
. filter ( |t| !matches ! ( t. token_kind, TokenKind :: Whitespace | TokenKind :: LineComment { .. } ) ) ;
859
882
// matches `!{`
860
883
match_tokens ! ( iter, Bang OpenBrace ) ;
861
- match iter. next ( ) {
884
+ let has_version = match iter. next ( ) {
862
885
// #[clippy::version = "version"] pub
863
886
Some ( LintDeclSearchResult {
864
887
token_kind : TokenKind :: Pound ,
865
888
..
866
889
} ) => {
867
890
match_tokens ! ( iter, OpenBracket Ident Colon Colon Ident Eq Literal { ..} CloseBracket Ident ) ;
891
+ true
868
892
} ,
869
893
// pub
870
894
Some ( LintDeclSearchResult {
871
895
token_kind : TokenKind :: Ident ,
872
896
..
873
- } ) => ( ) ,
897
+ } ) => false ,
874
898
_ => continue ,
875
- }
899
+ } ;
876
900
877
901
let ( name, group, desc) = match_tokens ! (
878
902
iter,
@@ -890,7 +914,7 @@ fn parse_contents(contents: &str, module: &str, lints: &mut Vec<Lint>) {
890
914
..
891
915
} ) = iter. next ( )
892
916
{
893
- lints. push ( Lint :: new ( name, group, desc, module, start..range. end ) ) ;
917
+ lints. push ( Lint :: new ( name, group, desc, module, has_version , start..range. end ) ) ;
894
918
}
895
919
}
896
920
}
0 commit comments