@@ -5,7 +5,7 @@ use clippy_utils::ty::implements_trait;
55use rustc_errors:: Applicability ;
66use rustc_hir:: { Expr , ExprKind , LangItem } ;
77use rustc_lint:: { LateContext , LateLintPass } ;
8- use rustc_middle:: ty:: { self , GenericArgKind , Ty } ;
8+ use rustc_middle:: ty:: { self , Ty } ;
99use rustc_session:: declare_lint_pass;
1010use rustc_span:: sym;
1111
@@ -38,7 +38,7 @@ impl LateLintPass<'_> for DefaultBoxAssignments {
3838 fn check_expr ( & mut self , cx : & LateContext < ' _ > , expr : & ' _ Expr < ' _ > ) {
3939 if let ExprKind :: Assign ( lhs, rhs, _) = & expr. kind {
4040 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 ( ) {
4242 span_lint_and_then (
4343 cx,
4444 DEFAULT_BOX_ASSIGNMENTS ,
@@ -64,28 +64,17 @@ impl LateLintPass<'_> for DefaultBoxAssignments {
6464 }
6565}
6666
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 {
6868 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 )
7471 {
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, & [ ] )
7873 } else {
7974 false
8075 }
8176}
8277
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) ) )
9180}
0 commit comments