@@ -5,7 +5,7 @@ use clippy_utils::ty::implements_trait;
5
5
use rustc_errors:: Applicability ;
6
6
use rustc_hir:: { Expr , ExprKind , LangItem } ;
7
7
use rustc_lint:: { LateContext , LateLintPass } ;
8
- use rustc_middle:: ty:: { self , GenericArgKind , Ty } ;
8
+ use rustc_middle:: ty:: { self , Ty } ;
9
9
use rustc_session:: declare_lint_pass;
10
10
use rustc_span:: sym;
11
11
@@ -38,7 +38,7 @@ impl LateLintPass<'_> for DefaultBoxAssignments {
38
38
fn check_expr ( & mut self , cx : & LateContext < ' _ > , expr : & ' _ Expr < ' _ > ) {
39
39
if let ExprKind :: Assign ( lhs, rhs, _) = & expr. kind {
40
40
let lhs_ty = cx. typeck_results ( ) . expr_ty ( lhs) ;
41
- if is_box_of_default ( lhs_ty , cx ) && is_default_call ( rhs , cx ) && !rhs. span . from_expansion ( ) {
41
+ if is_box_of_default ( cx , lhs_ty ) && is_default_call ( cx , rhs ) && !rhs. span . from_expansion ( ) {
42
42
span_lint_and_then (
43
43
cx,
44
44
DEFAULT_BOX_ASSIGNMENTS ,
@@ -64,28 +64,17 @@ impl LateLintPass<'_> for DefaultBoxAssignments {
64
64
}
65
65
}
66
66
67
- fn is_box_of_default < ' a > ( ty : Ty < ' a > , cx : & LateContext < ' a > ) -> bool {
67
+ fn is_box_of_default < ' tcx > ( cx : & LateContext < ' tcx > , ty : Ty < ' tcx > ) -> bool {
68
68
if let ty:: Adt ( def, args) = ty. kind ( )
69
- && cx. tcx . lang_items ( ) . get ( LangItem :: OwnedBox ) == Some ( def. did ( ) )
70
- && let Some ( inner) = args. iter ( ) . find_map ( |arg| match arg. kind ( ) {
71
- GenericArgKind :: Type ( ty) => Some ( ty) ,
72
- _ => None ,
73
- } )
69
+ && cx. tcx . is_lang_item ( def. did ( ) , LangItem :: OwnedBox )
70
+ && let Some ( default_trait_id) = cx. tcx . get_diagnostic_item ( sym:: Default )
74
71
{
75
- cx. tcx
76
- . get_diagnostic_item ( sym:: Default )
77
- . is_some_and ( |id| implements_trait ( cx, inner, id, & [ ] ) )
72
+ implements_trait ( cx, args. type_at ( 0 ) , default_trait_id, & [ ] )
78
73
} else {
79
74
false
80
75
}
81
76
}
82
77
83
- fn is_default_call ( expr : & Expr < ' _ > , cx : & LateContext < ' _ > ) -> bool {
84
- if let ExprKind :: Call ( func, _args) = expr. kind
85
- && is_default_equivalent_call ( cx, func, Some ( expr) )
86
- {
87
- true
88
- } else {
89
- false
90
- }
78
+ fn is_default_call ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> bool {
79
+ matches ! ( expr. kind, ExprKind :: Call ( func, _args) if is_default_equivalent_call( cx, func, Some ( expr) ) )
91
80
}
0 commit comments