Skip to content

Commit 01d2adc

Browse files
committed
replace get_box_inner_type with Ty::boxed_ty
1 parent e5e3bbd commit 01d2adc

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

clippy_lints/src/replace_box.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ use clippy_utils::sugg::Sugg;
33
use clippy_utils::ty::implements_trait;
44
use clippy_utils::{is_default_equivalent_call, local_is_initialized, path_def_id, path_to_local};
55
use rustc_errors::Applicability;
6-
use rustc_hir::{Expr, ExprKind, LangItem, QPath};
6+
use rustc_hir::{Expr, ExprKind, QPath};
77
use rustc_lint::{LateContext, LateLintPass};
8-
use rustc_middle::ty::{self, Ty};
98
use rustc_session::declare_lint_pass;
109
use rustc_span::sym;
1110

@@ -43,7 +42,7 @@ impl LateLintPass<'_> for ReplaceBox {
4342
&& let lhs_ty = cx.typeck_results().expr_ty(lhs)
4443
// No diagnostic for late-initialized locals
4544
&& 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()
4746
{
4847
if let Some(default_trait_id) = cx.tcx.get_diagnostic_item(sym::Default)
4948
&& implements_trait(cx, inner_ty, default_trait_id, &[])
@@ -94,16 +93,6 @@ impl LateLintPass<'_> for ReplaceBox {
9493
}
9594
}
9695

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-
10796
fn is_default_call(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
10897
matches!(expr.kind, ExprKind::Call(func, _args) if is_default_equivalent_call(cx, func, Some(expr)))
10998
}

0 commit comments

Comments
 (0)