@@ -350,16 +350,28 @@ impl<'tcx> LateLintPass<'tcx> for Types {
350350
351351 fn check_impl_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx ImplItem < ' _ > ) {
352352 match item. kind {
353- ImplItemKind :: Const ( ty, _) | ImplItemKind :: TyAlias ( ty) => self . check_ty (
354- cx,
355- ty,
356- CheckTyContext {
357- is_in_trait_impl : true ,
358- ..CheckTyContext :: default ( )
359- } ,
360- ) ,
361- // methods are covered by check_fn
362- ImplItemKind :: Fn ( ..) => ( ) ,
353+ ImplItemKind :: Const ( ty, _) => {
354+ let is_in_trait_impl = if let Some ( hir:: Node :: Item ( item) ) =
355+ cx. tcx . hir ( ) . find ( cx. tcx . hir ( ) . get_parent_item ( item. hir_id ( ) ) )
356+ {
357+ matches ! ( item. kind, ItemKind :: Impl ( hir:: Impl { of_trait: Some ( _) , .. } ) )
358+ } else {
359+ false
360+ } ;
361+
362+ self . check_ty (
363+ cx,
364+ ty,
365+ CheckTyContext {
366+ is_in_trait_impl,
367+ ..CheckTyContext :: default ( )
368+ } ,
369+ ) ;
370+ } ,
371+ // Methods are covered by check_fn.
372+ // Type aliases are ignored because oftentimes it's impossible to
373+ // make type alias declaration in trait simpler, see #1013
374+ ImplItemKind :: Fn ( ..) | ImplItemKind :: TyAlias ( ..) => ( ) ,
363375 }
364376 }
365377
@@ -417,6 +429,14 @@ impl Types {
417429 }
418430
419431 fn check_fn_decl ( & mut self , cx : & LateContext < ' _ > , decl : & FnDecl < ' _ > , context : CheckTyContext ) {
432+ // Ignore functions in trait implementations as they are usually forced by the trait definition.
433+ //
434+ // FIXME: idially we would like to warn *if the compicated type can be simplified*, but it's hard to
435+ // check.
436+ if context. is_in_trait_impl {
437+ return ;
438+ }
439+
420440 for input in decl. inputs {
421441 self . check_ty ( cx, input, context) ;
422442 }
@@ -435,12 +455,12 @@ impl Types {
435455 return ;
436456 }
437457
438- if !context. is_nested_call && type_complexity:: check ( cx, hir_ty, self . type_complexity_threshold ) {
458+ // Skip trait implementations; see issue #605.
459+ if context. is_in_trait_impl {
439460 return ;
440461 }
441462
442- // Skip trait implementations; see issue #605.
443- if context. is_in_trait_impl {
463+ if !context. is_nested_call && type_complexity:: check ( cx, hir_ty, self . type_complexity_threshold ) {
444464 return ;
445465 }
446466
0 commit comments