@@ -7,11 +7,12 @@ mod result;
77mod too_many_arguments;
88mod too_many_lines;
99
10+ use clippy_utils:: def_path_def_ids;
1011use rustc_hir as hir;
1112use rustc_hir:: intravisit;
1213use rustc_lint:: { LateContext , LateLintPass } ;
1314use rustc_session:: impl_lint_pass;
14- use rustc_span:: def_id:: LocalDefId ;
15+ use rustc_span:: def_id:: { DefIdSet , LocalDefId } ;
1516use rustc_span:: Span ;
1617
1718declare_clippy_lint ! {
@@ -373,19 +374,19 @@ declare_clippy_lint! {
373374 /// ```rust
374375 /// struct A(u32);
375376 ///
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
379380 /// }
380381 /// }
381382 /// ```
382383 /// Use instead:
383384 /// ```rust
384385 /// struct A(u32);
385386 ///
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
389390 /// }
390391 /// }
391392 /// ```
@@ -395,13 +396,16 @@ declare_clippy_lint! {
395396 "renamed function parameters in trait implementation"
396397}
397398
398- #[ derive( Copy , Clone ) ]
399- #[ allow( clippy:: struct_field_names) ]
399+ #[ derive( Clone ) ]
400400pub struct Functions {
401401 too_many_arguments_threshold : u64 ,
402402 too_many_lines_threshold : u64 ,
403403 large_error_threshold : u64 ,
404404 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 ,
405409}
406410
407411impl Functions {
@@ -410,12 +414,15 @@ impl Functions {
410414 too_many_lines_threshold : u64 ,
411415 large_error_threshold : u64 ,
412416 avoid_breaking_exported_api : bool ,
417+ allow_renamed_params_for : Vec < String > ,
413418 ) -> Self {
414419 Self {
415420 too_many_arguments_threshold,
416421 too_many_lines_threshold,
417422 large_error_threshold,
418423 avoid_breaking_exported_api,
424+ allow_renamed_params_for,
425+ trait_ids : DefIdSet :: default ( ) ,
419426 }
420427 }
421428}
@@ -461,7 +468,7 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
461468 must_use:: check_impl_item ( cx, item) ;
462469 result:: check_impl_item ( cx, item, self . large_error_threshold ) ;
463470 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 ) ;
465472 }
466473
467474 fn check_trait_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx hir:: TraitItem < ' _ > ) {
@@ -471,4 +478,12 @@ impl<'tcx> LateLintPass<'tcx> for Functions {
471478 result:: check_trait_item ( cx, item, self . large_error_threshold ) ;
472479 impl_trait_in_params:: check_trait_item ( cx, item, self . avoid_breaking_exported_api ) ;
473480 }
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+ }
474489}
0 commit comments