@@ -62,11 +62,14 @@ pub fn create(
6262
6363fn create_lint ( lint : & LintData < ' _ > , enable_msrv : bool ) -> io:: Result < ( ) > {
6464 if let Some ( ty) = lint. ty {
65- generate_from_ty ( lint, enable_msrv, ty)
65+ create_lint_for_ty ( lint, enable_msrv, ty)
6666 } else {
6767 let lint_contents = get_lint_file_contents ( lint, enable_msrv) ;
6868 let lint_path = format ! ( "clippy_lints/src/{}.rs" , lint. name) ;
69- write_file ( lint. project_root . join ( & lint_path) , lint_contents. as_bytes ( ) )
69+ write_file ( lint. project_root . join ( & lint_path) , lint_contents. as_bytes ( ) ) ?;
70+ println ! ( "Generated lint file: `{}`" , lint_path) ;
71+
72+ Ok ( ( ) )
7073 }
7174}
7275
@@ -86,16 +89,22 @@ fn create_test(lint: &LintData<'_>) -> io::Result<()> {
8689
8790 if lint. category == "cargo" {
8891 let relative_test_dir = format ! ( "tests/ui-cargo/{}" , lint. name) ;
89- let test_dir = lint. project_root . join ( relative_test_dir) ;
92+ let test_dir = lint. project_root . join ( & relative_test_dir) ;
9093 fs:: create_dir ( & test_dir) ?;
9194
9295 create_project_layout ( lint. name , & test_dir, "fail" , "Content that triggers the lint goes here" ) ?;
93- create_project_layout ( lint. name , & test_dir, "pass" , "This file should not trigger the lint" )
96+ create_project_layout ( lint. name , & test_dir, "pass" , "This file should not trigger the lint" ) ?;
97+
98+ println ! ( "Generated test directories: `{}`, `{}`" , format!( "{}/pass" , relative_test_dir) , format!( "{}/fail" , relative_test_dir) ) ;
9499 } else {
95100 let test_path = format ! ( "tests/ui/{}.rs" , lint. name) ;
96101 let test_contents = get_test_file_contents ( lint. name , None ) ;
97- write_file ( lint. project_root . join ( test_path) , test_contents)
102+ write_file ( lint. project_root . join ( & test_path) , test_contents) ?;
103+
104+ println ! ( "Generated test file: `{}`" , test_path) ;
98105 }
106+
107+ Ok ( ( ) )
99108}
100109
101110fn add_lint ( lint : & LintData < ' _ > , enable_msrv : bool ) -> io:: Result < ( ) > {
@@ -325,12 +334,14 @@ fn get_lint_declaration(name_upper: &str, category: &str) -> String {
325334 )
326335}
327336
328- fn generate_from_ty ( lint : & LintData < ' _ > , enable_msrv : bool , ty : & str ) -> io:: Result < ( ) > {
329- if ty == "cargo" {
330- assert_eq ! (
337+ fn create_lint_for_ty ( lint : & LintData < ' _ > , enable_msrv : bool , ty : & str ) -> io:: Result < ( ) > {
338+ match ty {
339+ "cargo" => assert_eq ! (
331340 lint. category, "cargo" ,
332341 "Lints of type `cargo` must have the `cargo` category"
333- ) ;
342+ ) ,
343+ _ if lint. category == "cargo" => panic ! ( "Lints of category `cargo` must have the `cargo` type" ) ,
344+ _ => { }
334345 }
335346
336347 let ty_dir = lint. project_root . join ( format ! ( "clippy_lints/src/{}" , ty) ) ;
@@ -392,7 +403,9 @@ fn generate_from_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::Res
392403 ) ;
393404 }
394405
395- write_file ( lint_file_path, lint_file_contents) ?;
406+ write_file ( lint_file_path. as_path ( ) , lint_file_contents) ?;
407+ println ! ( "Generated lint file: `clippy_lints/src/{}/{}.rs`" , ty, lint. name) ;
408+ println ! ( "Be sure to add a call to `{}::check` in `clippy_lints/src/{}/mod.rs`!" , lint. name, ty) ;
396409
397410 Ok ( ( ) )
398411}
0 commit comments