1+ // Run clippy on a fixed set of crates and collect the warnings.
2+ // This helps observing the impact clippy changs have on a set of real-world code.
3+ //
4+ // When a new lint is introduced, we can search the results for new warnings and check for false
5+ // positives.
6+
17#![ allow( clippy:: filter_map) ]
28
39use crate :: clippy_project_root;
4- use serde :: { Deserialize , Serialize } ;
10+
511use std:: collections:: HashMap ;
612use std:: process:: Command ;
713use std:: { fs:: write, path:: PathBuf } ;
814
15+ use serde:: { Deserialize , Serialize } ;
16+
917// crate data we stored in the toml, can have multiple versions.
1018// if so, one TomlKrate maps to several KrateSources
11- struct TomlKrate {
19+ struct TomlCrate {
1220 name : String ,
1321 versions : Vec < String > ,
1422}
1523
1624// represents an archive we download from crates.io
1725#[ derive( Debug , Serialize , Deserialize , Eq , Hash , PartialEq ) ]
18- struct KrateSource {
26+ struct CrateSource {
1927 name : String ,
2028 version : String ,
2129}
@@ -28,22 +36,15 @@ struct CrateList {
2836
2937// represents the extracted sourcecode of a crate
3038#[ derive( Debug ) ]
31- struct Krate {
39+ struct Crate {
3240 version : String ,
3341 name : String ,
3442 // path to the extracted sources that clippy can check
3543 path : PathBuf ,
3644}
3745
38- impl KrateSource {
39- fn new ( name : & str , version : & str ) -> Self {
40- KrateSource {
41- version : version. into ( ) ,
42- name : name. into ( ) ,
43- }
44- }
45-
46- fn download_and_extract ( & self ) -> Krate {
46+ impl CrateSource {
47+ fn download_and_extract ( & self ) -> Crate {
4748 let extract_dir = PathBuf :: from ( "target/crater/crates" ) ;
4849 let krate_download_dir = PathBuf :: from ( "target/crater/downloads" ) ;
4950
@@ -80,15 +81,15 @@ impl KrateSource {
8081 }
8182 // crate is extracted, return a new Krate object which contains the path to the extracted
8283 // sources that clippy can check
83- Krate {
84+ Crate {
8485 version : self . version . clone ( ) ,
8586 name : self . name . clone ( ) ,
8687 path : extract_dir. join ( format ! ( "{}-{}/" , self . name, self . version) ) ,
8788 }
8889 }
8990}
9091
91- impl Krate {
92+ impl Crate {
9293 fn run_clippy_lints ( & self , cargo_clippy_path : & PathBuf ) -> Vec < String > {
9394 println ! ( "Linting {} {}..." , & self . name, & self . version) ;
9495 let cargo_clippy_path = std:: fs:: canonicalize ( cargo_clippy_path) . unwrap ( ) ;
@@ -144,32 +145,32 @@ fn build_clippy() {
144145 . expect ( "Failed to build clippy!" ) ;
145146}
146147
147- // get a list of KrateSources we want to check from a "crater_crates.toml" file.
148- fn read_crates ( ) -> Vec < KrateSource > {
148+ // get a list of CrateSources we want to check from a "crater_crates.toml" file.
149+ fn read_crates ( ) -> Vec < CrateSource > {
149150 let toml_path = PathBuf :: from ( "clippy_dev/crater_crates.toml" ) ;
150151 let toml_content: String =
151152 std:: fs:: read_to_string ( & toml_path) . unwrap_or_else ( |_| panic ! ( "Failed to read {}" , toml_path. display( ) ) ) ;
152153 let crate_list: CrateList =
153154 toml:: from_str ( & toml_content) . unwrap_or_else ( |e| panic ! ( "Failed to parse {}: \n {}" , toml_path. display( ) , e) ) ;
154155 // parse the hashmap of the toml file into a list of crates
155- let tomlkrates : Vec < TomlKrate > = crate_list
156+ let tomlcrates : Vec < TomlCrate > = crate_list
156157 . crates
157158 . into_iter ( )
158- . map ( |( name, versions) | TomlKrate { name, versions } )
159+ . map ( |( name, versions) | TomlCrate { name, versions } )
159160 . collect ( ) ;
160161
161- // flatten TomlKrates into KrateSources (one TomlKrates may represent several versions of a crate =>
162- // multiple kratesources )
163- let mut krate_sources = Vec :: new ( ) ;
164- tomlkrates . into_iter ( ) . for_each ( |tk| {
162+ // flatten TomlCrates into CrateSources (one TomlCrates may represent several versions of a crate =>
163+ // multiple Cratesources )
164+ let mut crate_sources = Vec :: new ( ) ;
165+ tomlcrates . into_iter ( ) . for_each ( |tk| {
165166 tk. versions . iter ( ) . for_each ( |ver| {
166- krate_sources . push ( KrateSource {
167+ crate_sources . push ( CrateSource {
167168 name : tk. name . clone ( ) ,
168169 version : ver. to_string ( ) ,
169170 } ) ;
170171 } )
171172 } ) ;
172- krate_sources
173+ crate_sources
173174}
174175
175176// the main fn
0 commit comments