@@ -7,11 +7,12 @@ mod result;
7
7
mod too_many_arguments;
8
8
mod too_many_lines;
9
9
10
+ use clippy_utils:: def_path_def_ids;
10
11
use rustc_hir as hir;
11
12
use rustc_hir:: intravisit;
12
13
use rustc_lint:: { LateContext , LateLintPass } ;
13
14
use rustc_session:: impl_lint_pass;
14
- use rustc_span:: def_id:: LocalDefId ;
15
+ use rustc_span:: def_id:: { DefIdSet , LocalDefId } ;
15
16
use rustc_span:: Span ;
16
17
17
18
declare_clippy_lint ! {
@@ -373,19 +374,19 @@ declare_clippy_lint! {
373
374
/// ```rust
374
375
/// struct A(u32);
375
376
///
376
- /// impl From<A> for String {
377
- /// fn from(a: A ) -> Self {
378
- /// a.0.to_string()
377
+ /// impl PartialEq for A {
378
+ /// fn eq(&self, b: &Self ) -> bool {
379
+ /// self.0 == b.0
379
380
/// }
380
381
/// }
381
382
/// ```
382
383
/// Use instead:
383
384
/// ```rust
384
385
/// struct A(u32);
385
386
///
386
- /// impl From<A> for String {
387
- /// fn from(value: A ) -> Self {
388
- /// value.0.to_string()
387
+ /// impl PartialEq for A {
388
+ /// fn eq(&self, other: &Self ) -> bool {
389
+ /// self.0 == other.0
389
390
/// }
390
391
/// }
391
392
/// ```
@@ -395,13 +396,16 @@ declare_clippy_lint! {
395
396
"renamed function parameters in trait implementation"
396
397
}
397
398
398
- #[ derive( Copy , Clone ) ]
399
- #[ allow( clippy:: struct_field_names) ]
399
+ #[ derive( Clone ) ]
400
400
pub struct Functions {
401
401
too_many_arguments_threshold : u64 ,
402
402
too_many_lines_threshold : u64 ,
403
403
large_error_threshold : u64 ,
404
404
avoid_breaking_exported_api : bool ,
405
+ allow_renamed_params_for : Vec < String > ,
406
+ /// A set of resolved `def_id` of traits that are configured to allow
407
+ /// function params renaming.
408
+ trait_ids : DefIdSet ,
405
409
}
406
410
407
411
impl Functions {
@@ -410,12 +414,15 @@ impl Functions {
410
414
too_many_lines_threshold : u64 ,
411
415
large_error_threshold : u64 ,
412
416
avoid_breaking_exported_api : bool ,
417
+ allow_renamed_params_for : Vec < String > ,
413
418
) -> Self {
414
419
Self {
415
420
too_many_arguments_threshold,
416
421
too_many_lines_threshold,
417
422
large_error_threshold,
418
423
avoid_breaking_exported_api,
424
+ allow_renamed_params_for,
425
+ trait_ids : DefIdSet :: default ( ) ,
419
426
}
420
427
}
421
428
}
@@ -461,7 +468,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
461
468
must_use:: check_impl_item ( cx, item) ;
462
469
result:: check_impl_item ( cx, item, self . large_error_threshold ) ;
463
470
impl_trait_in_params:: check_impl_item ( cx, item) ;
464
- renamed_function_params:: check_impl_item ( cx, item) ;
471
+ renamed_function_params:: check_impl_item ( cx, item, & self . trait_ids ) ;
465
472
}
466
473
467
474
fn check_trait_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx hir:: TraitItem < ' _ > ) {
@@ -471,4 +478,12 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
471
478
result:: check_trait_item ( cx, item, self . large_error_threshold ) ;
472
479
impl_trait_in_params:: check_trait_item ( cx, item, self . avoid_breaking_exported_api ) ;
473
480
}
481
+
482
+ fn check_crate ( & mut self , cx : & LateContext < ' tcx > ) {
483
+ for path in & self . allow_renamed_params_for {
484
+ let path_segments: Vec < & str > = path. split ( "::" ) . collect ( ) ;
485
+ let ids = def_path_def_ids ( cx, & path_segments) ;
486
+ self . trait_ids . extend ( ids) ;
487
+ }
488
+ }
474
489
}
0 commit comments