@@ -2,13 +2,13 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg, span_lint_and_the
2
2
use clippy_utils:: source:: { SpanRangeExt , snippet_with_context} ;
3
3
use clippy_utils:: sugg:: { Sugg , has_enclosing_paren} ;
4
4
use clippy_utils:: ty:: implements_trait;
5
- use clippy_utils:: { get_item_name , get_parent_as_impl , is_lint_allowed , is_trait_method, peel_ref_operators} ;
5
+ use clippy_utils:: { fulfill_or_allowed , get_item_name , get_parent_as_impl , is_trait_method, peel_ref_operators} ;
6
6
use rustc_ast:: ast:: LitKind ;
7
7
use rustc_errors:: Applicability ;
8
8
use rustc_hir:: def:: Res ;
9
9
use rustc_hir:: def_id:: { DefId , DefIdSet } ;
10
10
use rustc_hir:: {
11
- AssocItemKind , BinOpKind , Expr , ExprKind , FnRetTy , GenericArg , GenericBound , ImplItem , ImplItemKind ,
11
+ AssocItemKind , BinOpKind , Expr , ExprKind , FnRetTy , GenericArg , GenericBound , HirId , ImplItem , ImplItemKind ,
12
12
ImplicitSelfKind , Item , ItemKind , Mutability , Node , OpaqueTyOrigin , PatExprKind , PatKind , PathSegment , PrimTy ,
13
13
QPath , TraitItemRef , TyKind ,
14
14
} ;
@@ -143,7 +143,6 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
143
143
&& let Some ( ty_id) = cx. qpath_res ( ty_path, imp. self_ty . hir_id ) . opt_def_id ( )
144
144
&& let Some ( local_id) = ty_id. as_local ( )
145
145
&& let ty_hir_id = cx. tcx . local_def_id_to_hir_id ( local_id)
146
- && !is_lint_allowed ( cx, LEN_WITHOUT_IS_EMPTY , ty_hir_id)
147
146
&& let Some ( output) =
148
147
parse_len_output ( cx, cx. tcx . fn_sig ( item. owner_id ) . instantiate_identity ( ) . skip_binder ( ) )
149
148
{
@@ -157,7 +156,17 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
157
156
} ,
158
157
_ => return ,
159
158
} ;
160
- check_for_is_empty ( cx, sig. span , sig. decl . implicit_self , output, ty_id, name, kind) ;
159
+ check_for_is_empty (
160
+ cx,
161
+ sig. span ,
162
+ sig. decl . implicit_self ,
163
+ output,
164
+ ty_id,
165
+ name,
166
+ kind,
167
+ item. hir_id ( ) ,
168
+ ty_hir_id,
169
+ ) ;
161
170
}
162
171
}
163
172
@@ -447,6 +456,7 @@ fn check_is_empty_sig<'tcx>(
447
456
}
448
457
449
458
/// Checks if the given type has an `is_empty` method with the appropriate signature.
459
+ #[ expect( clippy:: too_many_arguments) ]
450
460
fn check_for_is_empty (
451
461
cx : & LateContext < ' _ > ,
452
462
span : Span ,
@@ -455,6 +465,8 @@ fn check_for_is_empty(
455
465
impl_ty : DefId ,
456
466
item_name : Symbol ,
457
467
item_kind : & str ,
468
+ len_method_hir_id : HirId ,
469
+ ty_decl_hir_id : HirId ,
458
470
) {
459
471
// Implementor may be a type alias, in which case we need to get the `DefId` of the aliased type to
460
472
// find the correct inherent impls.
@@ -510,14 +522,16 @@ fn check_for_is_empty(
510
522
Some ( _) => return ,
511
523
} ;
512
524
513
- span_lint_and_then ( cx, LEN_WITHOUT_IS_EMPTY , span, msg, |db| {
514
- if let Some ( span) = is_empty_span {
515
- db. span_note ( span, "`is_empty` defined here" ) ;
516
- }
517
- if let Some ( self_kind) = self_kind {
518
- db. note ( output. expected_sig ( self_kind) ) ;
519
- }
520
- } ) ;
525
+ if !fulfill_or_allowed ( cx, LEN_WITHOUT_IS_EMPTY , [ len_method_hir_id, ty_decl_hir_id] ) {
526
+ span_lint_and_then ( cx, LEN_WITHOUT_IS_EMPTY , span, msg, |db| {
527
+ if let Some ( span) = is_empty_span {
528
+ db. span_note ( span, "`is_empty` defined here" ) ;
529
+ }
530
+ if let Some ( self_kind) = self_kind {
531
+ db. note ( output. expected_sig ( self_kind) ) ;
532
+ }
533
+ } ) ;
534
+ }
521
535
}
522
536
523
537
fn check_cmp ( cx : & LateContext < ' _ > , span : Span , method : & Expr < ' _ > , lit : & Expr < ' _ > , op : & str , compare_to : u32 ) {
0 commit comments