@@ -3,9 +3,8 @@ use clippy_utils::sugg::Sugg;
33use clippy_utils:: ty:: implements_trait;
44use clippy_utils:: { is_default_equivalent_call, local_is_initialized, path_def_id, path_to_local} ;
55use rustc_errors:: Applicability ;
6- use rustc_hir:: { Expr , ExprKind , LangItem , QPath } ;
6+ use rustc_hir:: { Expr , ExprKind , QPath } ;
77use rustc_lint:: { LateContext , LateLintPass } ;
8- use rustc_middle:: ty:: { self , Ty } ;
98use rustc_session:: declare_lint_pass;
109use rustc_span:: sym;
1110
@@ -40,20 +39,11 @@ impl LateLintPass<'_> for ReplaceBox {
4039 if let ExprKind :: Assign ( lhs, rhs, _) = & expr. kind
4140 && !lhs. span . from_expansion ( )
4241 && !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)
4643 // 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+ {
5747 if let Some ( default_trait_id) = cx. tcx . get_diagnostic_item ( sym:: Default )
5848 && implements_trait ( cx, inner_ty, default_trait_id, & [ ] )
5949 && is_default_call ( cx, rhs)
@@ -103,16 +93,6 @@ impl LateLintPass<'_> for ReplaceBox {
10393 }
10494}
10595
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-
11696fn is_default_call ( cx : & LateContext < ' _ > , expr : & Expr < ' _ > ) -> bool {
11797 matches ! ( expr. kind, ExprKind :: Call ( func, _args) if is_default_equivalent_call( cx, func, Some ( expr) ) )
11898}
0 commit comments