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} ;
4
2
use clippy_utils:: ty:: { implements_trait, implements_trait_with_env, is_copy} ;
5
3
use clippy_utils:: { is_lint_allowed, match_def_path, paths} ;
6
4
use if_chain:: if_chain;
7
5
use rustc_errors:: Applicability ;
8
6
use rustc_hir:: def_id:: DefId ;
9
7
use rustc_hir:: intravisit:: { walk_expr, walk_fn, walk_item, FnKind , Visitor } ;
10
8
use 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 ,
13
10
} ;
14
11
use rustc_lint:: { LateContext , LateLintPass } ;
15
12
use rustc_middle:: hir:: nested_filter;
16
13
use rustc_middle:: traits:: Reveal ;
17
14
use 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 ,
20
17
} ;
21
18
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
22
19
use rustc_span:: def_id:: LocalDefId ;
@@ -207,10 +204,13 @@ declare_lint_pass!(Derive => [
207
204
208
205
impl < ' tcx > LateLintPass < ' tcx > for Derive {
209
206
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
+ {
211
212
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) ;
214
214
215
215
check_hash_peq ( cx, item. span , trait_ref, ty, is_automatically_derived) ;
216
216
check_ord_partial_ord ( cx, item. span , trait_ref, ty, is_automatically_derived) ;
@@ -327,12 +327,7 @@ fn check_ord_partial_ord<'tcx>(
327
327
}
328
328
329
329
/// 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 > ) {
336
331
let clone_id = match cx. tcx . lang_items ( ) . clone_trait ( ) {
337
332
Some ( id) if trait_ref. trait_def_id ( ) == Some ( id) => id,
338
333
_ => return ,
@@ -350,9 +345,10 @@ fn check_copy_clone<'tcx>(
350
345
if !is_copy ( cx, ty) {
351
346
if ty_subs. non_erasable_generics ( ) . next ( ) . is_some ( ) {
352
347
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
+ } )
356
352
} ) ;
357
353
if !has_copy_impl {
358
354
return ;
@@ -431,14 +427,7 @@ struct UnsafeVisitor<'a, 'tcx> {
431
427
impl < ' tcx > Visitor < ' tcx > for UnsafeVisitor < ' _ , ' tcx > {
432
428
type NestedFilter = nested_filter:: All ;
433
429
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 ) {
442
431
if self . has_unsafe {
443
432
return ;
444
433
}
@@ -474,12 +463,7 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
474
463
}
475
464
476
465
/// 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 > ) {
483
467
if_chain ! {
484
468
if let ty:: Adt ( adt, args) = ty. kind( ) ;
485
469
if cx. tcx. visibility( adt. did( ) ) . is_public( ) ;
0 commit comments