@@ -170,29 +170,34 @@ pub fn gather_all() -> impl Iterator<Item = Lint> {
170
170
171
171
fn gather_from_file ( dir_entry : & walkdir:: DirEntry ) -> impl Iterator < Item = Lint > {
172
172
let content = fs:: read_to_string ( dir_entry. path ( ) ) . unwrap ( ) ;
173
- let mut filename = dir_entry. path ( ) . file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
173
+ let path = dir_entry. path ( ) ;
174
+ let filename = path. file_stem ( ) . unwrap ( ) ;
175
+ let path_buf = path. with_file_name ( filename) ;
176
+ let mut rel_path = path_buf
177
+ . strip_prefix ( clippy_project_root ( ) . join ( "clippy_lints/src" ) )
178
+ . expect ( "only files in `clippy_lints/src` should be looked at" ) ;
174
179
// If the lints are stored in mod.rs, we get the module name from
175
180
// the containing directory:
176
181
if filename == "mod" {
177
- filename = dir_entry
178
- . path ( )
179
- . parent ( )
180
- . unwrap ( )
181
- . file_stem ( )
182
- . unwrap ( )
183
- . to_str ( )
184
- . unwrap ( )
182
+ rel_path = rel_path. parent ( ) . unwrap ( ) ;
185
183
}
186
- parse_contents ( & content, filename)
184
+
185
+ let module = rel_path
186
+ . components ( )
187
+ . map ( |c| c. as_os_str ( ) . to_str ( ) . unwrap ( ) )
188
+ . collect :: < Vec < _ > > ( )
189
+ . join ( "::" ) ;
190
+
191
+ parse_contents ( & content, & module)
187
192
}
188
193
189
- fn parse_contents ( content : & str , filename : & str ) -> impl Iterator < Item = Lint > {
194
+ fn parse_contents ( content : & str , module : & str ) -> impl Iterator < Item = Lint > {
190
195
let lints = DEC_CLIPPY_LINT_RE
191
196
. captures_iter ( content)
192
- . map ( |m| Lint :: new ( & m[ "name" ] , & m[ "cat" ] , & m[ "desc" ] , None , filename ) ) ;
197
+ . map ( |m| Lint :: new ( & m[ "name" ] , & m[ "cat" ] , & m[ "desc" ] , None , module ) ) ;
193
198
let deprecated = DEC_DEPRECATED_LINT_RE
194
199
. captures_iter ( content)
195
- . map ( |m| Lint :: new ( & m[ "name" ] , "Deprecated" , & m[ "desc" ] , Some ( & m[ "desc" ] ) , filename ) ) ;
200
+ . map ( |m| Lint :: new ( & m[ "name" ] , "Deprecated" , & m[ "desc" ] , Some ( & m[ "desc" ] ) , module ) ) ;
196
201
// Removing the `.collect::<Vec<Lint>>().into_iter()` causes some lifetime issues due to the map
197
202
lints. chain ( deprecated) . collect :: < Vec < Lint > > ( ) . into_iter ( )
198
203
}
0 commit comments