@@ -114,19 +114,22 @@ pub fn gen_changelog_lint_list(lints: Vec<Lint>) -> Vec<String> {
114
114
115
115
/// Generates the `register_removed` code in `./clippy_lints/src/lib.rs`.
116
116
pub fn gen_deprecated ( lints : & [ Lint ] ) -> Vec < String > {
117
- lints. iter ( )
118
- . filter_map ( |l| {
119
- l. clone ( ) . deprecation . and_then ( |depr_text| {
120
- Some (
121
- format ! (
122
- " store.register_removed(\n \" {}\" ,\n \" {}\" ,\n );" ,
123
- l. name,
124
- depr_text
117
+ itertools:: flatten (
118
+ lints
119
+ . iter ( )
120
+ . filter_map ( |l| {
121
+ l. clone ( ) . deprecation . and_then ( |depr_text| {
122
+ Some (
123
+ vec ! [
124
+ " store.register_removed(" . to_string( ) ,
125
+ format!( " \" {}\" ," , l. name) ,
126
+ format!( " \" {}\" ," , depr_text) ,
127
+ " );" . to_string( )
128
+ ]
125
129
)
126
- )
130
+ } )
127
131
} )
128
- } )
129
- . collect ( )
132
+ ) . collect ( )
130
133
}
131
134
132
135
/// Gathers all files in `src/clippy_lints` and gathers all lints inside
@@ -258,6 +261,7 @@ pub fn replace_region_in_text<F>(text: &str, start: &str, end: &str, replace_sta
258
261
// is incorrect.
259
262
eprintln ! ( "error: regex `{:?}` not found. You may have to update it." , start) ;
260
263
}
264
+
261
265
FileChange {
262
266
changed : lines. ne ( new_lines. clone ( ) ) ,
263
267
new_lines : new_lines. join ( "\n " )
@@ -305,38 +309,40 @@ declare_deprecated_lint! {
305
309
306
310
#[ test]
307
311
fn test_replace_region ( ) {
308
- let text = r#"
309
- abc
310
- 123
311
- 789
312
- def
313
- ghi"# ;
314
- let expected = r#"
315
- abc
316
- hello world
317
- def
318
- ghi"# ;
312
+ let text = "\n abc\n 123\n 789\n def\n ghi" ;
313
+ let expected = FileChange {
314
+ changed : true ,
315
+ new_lines : "\n abc\n hello world\n def\n ghi" . to_string ( )
316
+ } ;
319
317
let result = replace_region_in_text ( text, r#"^\s*abc$"# , r#"^\s*def"# , false , || {
320
318
vec ! [ "hello world" . to_string( ) ]
321
- } ) . new_lines ;
319
+ } ) ;
322
320
assert_eq ! ( expected, result) ;
323
321
}
324
322
325
323
#[ test]
326
324
fn test_replace_region_with_start ( ) {
327
- let text = r#"
328
- abc
329
- 123
330
- 789
331
- def
332
- ghi"# ;
333
- let expected = r#"
334
- hello world
335
- def
336
- ghi"# ;
325
+ let text = "\n abc\n 123\n 789\n def\n ghi" ;
326
+ let expected = FileChange {
327
+ changed : true ,
328
+ new_lines : "\n hello world\n def\n ghi" . to_string ( )
329
+ } ;
337
330
let result = replace_region_in_text ( text, r#"^\s*abc$"# , r#"^\s*def"# , true , || {
338
331
vec ! [ "hello world" . to_string( ) ]
339
- } ) . new_lines ;
332
+ } ) ;
333
+ assert_eq ! ( expected, result) ;
334
+ }
335
+
336
+ #[ test]
337
+ fn test_replace_region_no_changes ( ) {
338
+ let text = "123\n 456\n 789" ;
339
+ let expected = FileChange {
340
+ changed : false ,
341
+ new_lines : "123\n 456\n 789" . to_string ( )
342
+ } ;
343
+ let result = replace_region_in_text ( text, r#"^\s*123$"# , r#"^\s*456"# , false , || {
344
+ vec ! [ ]
345
+ } ) ;
340
346
assert_eq ! ( expected, result) ;
341
347
}
342
348
@@ -390,14 +396,19 @@ fn test_gen_changelog_lint_list() {
390
396
fn test_gen_deprecated ( ) {
391
397
let lints = vec ! [
392
398
Lint :: new( "should_assert_eq" , "group1" , "abc" , Some ( "has been superseeded by should_assert_eq2" ) , "module_name" ) ,
399
+ Lint :: new( "another_deprecated" , "group2" , "abc" , Some ( "will be removed" ) , "module_name" ) ,
393
400
Lint :: new( "should_assert_eq2" , "group2" , "abc" , None , "module_name" )
394
401
] ;
395
402
let expected: Vec < String > = vec ! [
396
- r#" store.register_removed(
397
- "should_assert_eq",
398
- "has been superseeded by should_assert_eq2",
399
- );"# . to_string( )
400
- ] ;
403
+ " store.register_removed(" ,
404
+ " \" should_assert_eq\" ," ,
405
+ " \" has been superseeded by should_assert_eq2\" ," ,
406
+ " );" ,
407
+ " store.register_removed(" ,
408
+ " \" another_deprecated\" ," ,
409
+ " \" will be removed\" ," ,
410
+ " );"
411
+ ] . into_iter ( ) . map ( String :: from) . collect ( ) ;
401
412
assert_eq ! ( expected, gen_deprecated( & lints) ) ;
402
413
}
403
414
0 commit comments