@@ -61,13 +61,15 @@ impl Lint {
6161 lints. filter ( |l| l. deprecation . is_none ( ) && !l. is_internal ( ) )
6262 }
6363
64+ /// Returns all internal lints (not `internal_warn` lints)
65+ pub fn internal_lints ( lints : impl Iterator < Item = Self > ) -> impl Iterator < Item = Self > {
66+ lints. filter ( |l| l. group == "internal" )
67+ }
68+
6469 /// Returns the lints in a `HashMap`, grouped by the different lint groups
6570 #[ must_use]
66- pub fn by_lint_group ( lints : & [ Self ] ) -> HashMap < String , Vec < Self > > {
67- lints
68- . iter ( )
69- . map ( |lint| ( lint. group . to_string ( ) , lint. clone ( ) ) )
70- . into_group_map ( )
71+ pub fn by_lint_group ( lints : impl Iterator < Item = Self > ) -> HashMap < String , Vec < Self > > {
72+ lints. map ( |lint| ( lint. group . to_string ( ) , lint) ) . into_group_map ( )
7173 }
7274
7375 #[ must_use]
@@ -82,7 +84,7 @@ pub fn gen_lint_group_list(lints: Vec<Lint>) -> Vec<String> {
8284 lints
8385 . into_iter ( )
8486 . filter_map ( |l| {
85- if l. is_internal ( ) || l . deprecation . is_some ( ) {
87+ if l. deprecation . is_some ( ) {
8688 None
8789 } else {
8890 Some ( format ! ( " LintId::of(&{}::{})," , l. module, l. name. to_uppercase( ) ) )
@@ -173,29 +175,34 @@ pub fn gather_all() -> impl Iterator<Item = Lint> {
173175
174176fn gather_from_file ( dir_entry : & walkdir:: DirEntry ) -> impl Iterator < Item = Lint > {
175177 let content = fs:: read_to_string ( dir_entry. path ( ) ) . unwrap ( ) ;
176- let mut filename = dir_entry. path ( ) . file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
178+ let path = dir_entry. path ( ) ;
179+ let filename = path. file_stem ( ) . unwrap ( ) ;
180+ let path_buf = path. with_file_name ( filename) ;
181+ let mut rel_path = path_buf
182+ . strip_prefix ( clippy_project_root ( ) . join ( "clippy_lints/src" ) )
183+ . expect ( "only files in `clippy_lints/src` should be looked at" ) ;
177184 // If the lints are stored in mod.rs, we get the module name from
178185 // the containing directory:
179186 if filename == "mod" {
180- filename = dir_entry
181- . path ( )
182- . parent ( )
183- . unwrap ( )
184- . file_stem ( )
185- . unwrap ( )
186- . to_str ( )
187- . unwrap ( )
187+ rel_path = rel_path. parent ( ) . unwrap ( ) ;
188188 }
189- parse_contents ( & content, filename)
189+
190+ let module = rel_path
191+ . components ( )
192+ . map ( |c| c. as_os_str ( ) . to_str ( ) . unwrap ( ) )
193+ . collect :: < Vec < _ > > ( )
194+ . join ( "::" ) ;
195+
196+ parse_contents ( & content, & module)
190197}
191198
192- fn parse_contents ( content : & str , filename : & str ) -> impl Iterator < Item = Lint > {
199+ fn parse_contents ( content : & str , module : & str ) -> impl Iterator < Item = Lint > {
193200 let lints = DEC_CLIPPY_LINT_RE
194201 . captures_iter ( content)
195- . map ( |m| Lint :: new ( & m[ "name" ] , & m[ "cat" ] , & m[ "desc" ] , None , filename ) ) ;
202+ . map ( |m| Lint :: new ( & m[ "name" ] , & m[ "cat" ] , & m[ "desc" ] , None , module ) ) ;
196203 let deprecated = DEC_DEPRECATED_LINT_RE
197204 . captures_iter ( content)
198- . map ( |m| Lint :: new ( & m[ "name" ] , "Deprecated" , & m[ "desc" ] , Some ( & m[ "desc" ] ) , filename ) ) ;
205+ . map ( |m| Lint :: new ( & m[ "name" ] , "Deprecated" , & m[ "desc" ] , Some ( & m[ "desc" ] ) , module ) ) ;
199206 // Removing the `.collect::<Vec<Lint>>().into_iter()` causes some lifetime issues due to the map
200207 lints. chain ( deprecated) . collect :: < Vec < Lint > > ( ) . into_iter ( )
201208}
@@ -449,7 +456,7 @@ fn test_by_lint_group() {
449456 "group2" . to_string ( ) ,
450457 vec ! [ Lint :: new( "should_assert_eq2" , "group2" , "abc" , None , "module_name" ) ] ,
451458 ) ;
452- assert_eq ! ( expected, Lint :: by_lint_group( & lints) ) ;
459+ assert_eq ! ( expected, Lint :: by_lint_group( lints. into_iter ( ) ) ) ;
453460}
454461
455462#[ test]
@@ -522,10 +529,11 @@ fn test_gen_lint_group_list() {
522529 Lint :: new( "abc" , "group1" , "abc" , None , "module_name" ) ,
523530 Lint :: new( "should_assert_eq" , "group1" , "abc" , None , "module_name" ) ,
524531 Lint :: new( "should_assert_eq2" , "group2" , "abc" , Some ( "abc" ) , "deprecated" ) ,
525- Lint :: new( "incorrect_internal " , "internal_style" , "abc" , None , "module_name" ) ,
532+ Lint :: new( "internal " , "internal_style" , "abc" , None , "module_name" ) ,
526533 ] ;
527534 let expected = vec ! [
528535 " LintId::of(&module_name::ABC)," . to_string( ) ,
536+ " LintId::of(&module_name::INTERNAL)," . to_string( ) ,
529537 " LintId::of(&module_name::SHOULD_ASSERT_EQ)," . to_string( ) ,
530538 ] ;
531539 assert_eq ! ( expected, gen_lint_group_list( lints) ) ;
0 commit comments