1- use clippy_utils:: diagnostics:: {
2- span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then,
3- } ;
1+ use clippy_utils:: diagnostics:: { span_lint_and_help, span_lint_and_note, span_lint_and_sugg, span_lint_and_then} ;
42use clippy_utils:: ty:: { implements_trait, implements_trait_with_env, is_copy} ;
53use clippy_utils:: { is_lint_allowed, match_def_path, paths} ;
64use if_chain:: if_chain;
75use rustc_errors:: Applicability ;
86use rustc_hir:: def_id:: DefId ;
97use rustc_hir:: intravisit:: { walk_expr, walk_fn, walk_item, FnKind , Visitor } ;
108use rustc_hir:: {
11- self as hir, BlockCheckMode , BodyId , Expr , ExprKind , FnDecl , Impl , Item , ItemKind ,
12- UnsafeSource , Unsafety ,
9+ self as hir, BlockCheckMode , BodyId , Expr , ExprKind , FnDecl , Impl , Item , ItemKind , UnsafeSource , Unsafety ,
1310} ;
1411use rustc_lint:: { LateContext , LateLintPass } ;
1512use rustc_middle:: hir:: nested_filter;
1613use rustc_middle:: traits:: Reveal ;
1714use rustc_middle:: ty:: {
18- self , ClauseKind , GenericArgKind , GenericParamDefKind , ImplPolarity , ParamEnv ,
19- ToPredicate , TraitPredicate , Ty , TyCtxt ,
15+ self , ClauseKind , GenericArgKind , GenericParamDefKind , ImplPolarity , ParamEnv , ToPredicate , TraitPredicate , Ty ,
16+ TyCtxt ,
2017} ;
2118use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
2219use rustc_span:: def_id:: LocalDefId ;
@@ -207,10 +204,13 @@ declare_lint_pass!(Derive => [
207204
208205impl < ' tcx > LateLintPass < ' tcx > for Derive {
209206 fn check_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx Item < ' _ > ) {
210- if let ItemKind :: Impl ( Impl { of_trait : Some ( ref trait_ref) , .. } ) = item. kind {
207+ if let ItemKind :: Impl ( Impl {
208+ of_trait : Some ( ref trait_ref) ,
209+ ..
210+ } ) = item. kind
211+ {
211212 let ty = cx. tcx . type_of ( item. owner_id ) . instantiate_identity ( ) ;
212- let is_automatically_derived =
213- cx. tcx . has_attr ( item. owner_id , sym:: automatically_derived) ;
213+ let is_automatically_derived = cx. tcx . has_attr ( item. owner_id , sym:: automatically_derived) ;
214214
215215 check_hash_peq ( cx, item. span , trait_ref, ty, is_automatically_derived) ;
216216 check_ord_partial_ord ( cx, item. span , trait_ref, ty, is_automatically_derived) ;
@@ -327,12 +327,7 @@ fn check_ord_partial_ord<'tcx>(
327327}
328328
329329/// Implementation of the `EXPL_IMPL_CLONE_ON_COPY` lint.
330- fn check_copy_clone < ' tcx > (
331- cx : & LateContext < ' tcx > ,
332- item : & Item < ' _ > ,
333- trait_ref : & hir:: TraitRef < ' _ > ,
334- ty : Ty < ' tcx > ,
335- ) {
330+ fn check_copy_clone < ' tcx > ( cx : & LateContext < ' tcx > , item : & Item < ' _ > , trait_ref : & hir:: TraitRef < ' _ > , ty : Ty < ' tcx > ) {
336331 let clone_id = match cx. tcx . lang_items ( ) . clone_trait ( ) {
337332 Some ( id) if trait_ref. trait_def_id ( ) == Some ( id) => id,
338333 _ => return ,
@@ -350,9 +345,10 @@ fn check_copy_clone<'tcx>(
350345 if !is_copy ( cx, ty) {
351346 if ty_subs. non_erasable_generics ( ) . next ( ) . is_some ( ) {
352347 let has_copy_impl = cx. tcx . all_local_trait_impls ( ( ) ) . get ( & copy_id) . map_or ( false , |impls| {
353- impls
354- . iter ( )
355- . any ( |& id| matches ! ( cx. tcx. type_of( id) . instantiate_identity( ) . kind( ) , ty:: Adt ( adt, _) if ty_adt. did( ) == adt. did( ) ) )
348+ impls. iter ( ) . any ( |& id| {
349+ matches ! ( cx. tcx. type_of( id) . instantiate_identity( ) . kind( ) , ty:: Adt ( adt, _)
350+ if ty_adt. did( ) == adt. did( ) )
351+ } )
356352 } ) ;
357353 if !has_copy_impl {
358354 return ;
@@ -431,14 +427,7 @@ struct UnsafeVisitor<'a, 'tcx> {
431427impl < ' tcx > Visitor < ' tcx > for UnsafeVisitor < ' _ , ' tcx > {
432428 type NestedFilter = nested_filter:: All ;
433429
434- fn visit_fn (
435- & mut self ,
436- kind : FnKind < ' tcx > ,
437- decl : & ' tcx FnDecl < ' _ > ,
438- body_id : BodyId ,
439- _: Span ,
440- id : LocalDefId ,
441- ) {
430+ fn visit_fn ( & mut self , kind : FnKind < ' tcx > , decl : & ' tcx FnDecl < ' _ > , body_id : BodyId , _: Span , id : LocalDefId ) {
442431 if self . has_unsafe {
443432 return ;
444433 }
@@ -474,12 +463,7 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
474463}
475464
476465/// Implementation of the `DERIVE_PARTIAL_EQ_WITHOUT_EQ` lint.
477- fn check_partial_eq_without_eq < ' tcx > (
478- cx : & LateContext < ' tcx > ,
479- span : Span ,
480- trait_ref : & hir:: TraitRef < ' _ > ,
481- ty : Ty < ' tcx > ,
482- ) {
466+ fn check_partial_eq_without_eq < ' tcx > ( cx : & LateContext < ' tcx > , span : Span , trait_ref : & hir:: TraitRef < ' _ > , ty : Ty < ' tcx > ) {
483467 if_chain ! {
484468 if let ty:: Adt ( adt, args) = ty. kind( ) ;
485469 if cx. tcx. visibility( adt. did( ) ) . is_public( ) ;
0 commit comments