@@ -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
@@ -43,7 +42,7 @@ impl LateLintPass<'_> for ReplaceBox {
43
42
&& let lhs_ty = cx. typeck_results ( ) . expr_ty ( lhs)
44
43
// No diagnostic for late-initialized locals
45
44
&& path_to_local ( lhs) . is_none_or ( |local| local_is_initialized ( cx, local) )
46
- && let Some ( inner_ty) = get_box_inner_type ( cx , lhs_ty)
45
+ && let Some ( inner_ty) = lhs_ty. boxed_ty ( )
47
46
{
48
47
if let Some ( default_trait_id) = cx. tcx . get_diagnostic_item ( sym:: Default )
49
48
&& implements_trait ( cx, inner_ty, default_trait_id, & [ ] )
@@ -94,16 +93,6 @@ impl LateLintPass<'_> for ReplaceBox {
94
93
}
95
94
}
96
95
97
- fn get_box_inner_type < ' tcx > ( cx : & LateContext < ' tcx > , ty : Ty < ' tcx > ) -> Option < Ty < ' tcx > > {
98
- if let ty:: Adt ( def, args) = ty. kind ( )
99
- && cx. tcx . is_lang_item ( def. did ( ) , LangItem :: OwnedBox )
100
- {
101
- Some ( args. type_at ( 0 ) )
102
- } else {
103
- None
104
- }
105
- }
106
-
107
96
fn is_default_call ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> bool {
108
97
matches ! ( expr. kind, ExprKind :: Call ( func, _args) if is_default_equivalent_call( cx, func, Some ( expr) ) )
109
98
}
0 commit comments