@@ -3,9 +3,8 @@ use clippy_utils::sugg::Sugg;
3
3
use clippy_utils:: ty:: implements_trait;
4
4
use clippy_utils:: { is_default_equivalent_call, local_is_initialized, path_def_id, path_to_local} ;
5
5
use rustc_errors:: Applicability ;
6
- use rustc_hir:: { Expr , ExprKind , LangItem , QPath } ;
6
+ use rustc_hir:: { Expr , ExprKind , QPath } ;
7
7
use rustc_lint:: { LateContext , LateLintPass } ;
8
- use rustc_middle:: ty:: { self , Ty } ;
9
8
use rustc_session:: declare_lint_pass;
10
9
use rustc_span:: sym;
11
10
@@ -40,20 +39,11 @@ impl LateLintPass<'_> for ReplaceBox {
40
39
if let ExprKind :: Assign ( lhs, rhs, _) = & expr. kind
41
40
&& !lhs. span . from_expansion ( )
42
41
&& !rhs. span . from_expansion ( )
43
- {
44
- let lhs_ty = cx. typeck_results ( ) . expr_ty ( lhs) ;
45
-
42
+ && let lhs_ty = cx. typeck_results ( ) . expr_ty ( lhs)
46
43
// No diagnostic for late-initialized locals
47
- if let Some ( local) = path_to_local ( lhs)
48
- && !local_is_initialized ( cx, local)
49
- {
50
- return ;
51
- }
52
-
53
- let Some ( inner_ty) = get_box_inner_type ( cx, lhs_ty) else {
54
- return ;
55
- } ;
56
-
44
+ && path_to_local ( lhs) . is_none_or ( |local| local_is_initialized ( cx, local) )
45
+ && let Some ( inner_ty) = lhs_ty. boxed_ty ( )
46
+ {
57
47
if let Some ( default_trait_id) = cx. tcx . get_diagnostic_item ( sym:: Default )
58
48
&& implements_trait ( cx, inner_ty, default_trait_id, & [ ] )
59
49
&& is_default_call ( cx, rhs)
@@ -103,16 +93,6 @@ impl LateLintPass<'_> for ReplaceBox {
103
93
}
104
94
}
105
95
106
- fn get_box_inner_type < ' tcx > ( cx : & LateContext < ' tcx > , ty : Ty < ' tcx > ) -> Option < Ty < ' tcx > > {
107
- if let ty:: Adt ( def, args) = ty. kind ( )
108
- && cx. tcx . is_lang_item ( def. did ( ) , LangItem :: OwnedBox )
109
- {
110
- Some ( args. type_at ( 0 ) )
111
- } else {
112
- None
113
- }
114
- }
115
-
116
96
fn is_default_call ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> bool {
117
97
matches ! ( expr. kind, ExprKind :: Call ( func, _args) if is_default_equivalent_call( cx, func, Some ( expr) ) )
118
98
}
0 commit comments