@@ -50,21 +50,6 @@ impl ExtraUnusedTypeParameters {
50
50
avoid_breaking_exported_api,
51
51
}
52
52
}
53
-
54
- /// Don't lint external macros or functions with empty bodies. Also, don't lint exported items
55
- /// if the `avoid_breaking_exported_api` config option is set.
56
- fn is_empty_exported_or_macro (
57
- & self ,
58
- cx : & LateContext < ' _ > ,
59
- span : Span ,
60
- def_id : LocalDefId ,
61
- body_id : BodyId ,
62
- ) -> bool {
63
- let body = cx. tcx . hir ( ) . body ( body_id) . value ;
64
- let fn_empty = matches ! ( & body. kind, ExprKind :: Block ( blk, None ) if blk. stmts. is_empty( ) && blk. expr. is_none( ) ) ;
65
- let is_exported = cx. effective_visibilities . is_exported ( def_id) ;
66
- in_external_macro ( cx. sess ( ) , span) || fn_empty || ( is_exported && self . avoid_breaking_exported_api )
67
- }
68
53
}
69
54
70
55
impl_lint_pass ! ( ExtraUnusedTypeParameters => [ EXTRA_UNUSED_TYPE_PARAMETERS ] ) ;
@@ -266,10 +251,17 @@ impl<'cx, 'tcx> Visitor<'tcx> for TypeWalker<'cx, 'tcx> {
266
251
}
267
252
}
268
253
254
+ fn is_empty_body ( cx : & LateContext < ' _ > , body : BodyId ) -> bool {
255
+ matches ! ( cx. tcx. hir( ) . body( body) . value. kind, ExprKind :: Block ( b, _) if b. stmts. is_empty( ) && b. expr. is_none( ) )
256
+ }
257
+
269
258
impl < ' tcx > LateLintPass < ' tcx > for ExtraUnusedTypeParameters {
270
259
fn check_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx Item < ' tcx > ) {
271
260
if let ItemKind :: Fn ( _, generics, body_id) = item. kind
272
- && !self . is_empty_exported_or_macro ( cx, item. span , item. owner_id . def_id , body_id)
261
+ && !generics. params . is_empty ( )
262
+ && !is_empty_body ( cx, body_id)
263
+ && ( !self . avoid_breaking_exported_api || !cx. effective_visibilities . is_exported ( item. owner_id . def_id ) )
264
+ && !in_external_macro ( cx. sess ( ) , item. span )
273
265
&& !is_from_proc_macro ( cx, item)
274
266
{
275
267
let mut walker = TypeWalker :: new ( cx, generics) ;
@@ -281,8 +273,12 @@ impl<'tcx> LateLintPass<'tcx> for ExtraUnusedTypeParameters {
281
273
fn check_impl_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx ImplItem < ' tcx > ) {
282
274
// Only lint on inherent methods, not trait methods.
283
275
if let ImplItemKind :: Fn ( .., body_id) = item. kind
276
+ && !item. generics . params . is_empty ( )
284
277
&& trait_ref_of_method ( cx, item. owner_id . def_id ) . is_none ( )
285
- && !self . is_empty_exported_or_macro ( cx, item. span , item. owner_id . def_id , body_id)
278
+ && !is_empty_body ( cx, body_id)
279
+ && ( !self . avoid_breaking_exported_api || !cx. effective_visibilities . is_exported ( item. owner_id . def_id ) )
280
+ && !in_external_macro ( cx. sess ( ) , item. span )
281
+ && !is_from_proc_macro ( cx, item)
286
282
{
287
283
let mut walker = TypeWalker :: new ( cx, item. generics ) ;
288
284
walk_impl_item ( & mut walker, item) ;
0 commit comments