Skip to content

Commit

Permalink
Added some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
botahamec committed Jul 3, 2022
1 parent 2cdba4a commit 60df7e4
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions clippy_lints/src/unused_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,15 @@ impl LateLintPass<'_> for UnusedBox {
_: Span,
_: HirId,
) {
// it's unclear what part of a closure you would span, so for now it's ignored
// if this is changed, please also make sure not to call `hir_ty_to_ty` below
if let FnKind::Closure = fn_kind {
return;
}

let FnRetTy::Return(return_ty_hir) = &decl.output else { return };

// this is safe, since we're not in a body
let return_ty = hir_ty_to_ty(cx.tcx, return_ty_hir);

if !return_ty.is_box() {
Expand All @@ -57,6 +62,7 @@ impl LateLintPass<'_> for UnusedBox {
let boxed_ty = return_ty.boxed_ty();
let Some(sized_trait) = cx.tcx.lang_items().sized_trait() else { return };

// it's sometimes useful to return Box<T> if T is unsized, so don't lint those
if implements_trait(cx, boxed_ty, sized_trait, &[]) {
span_lint_and_sugg(
cx,
Expand Down

0 comments on commit 60df7e4

Please sign in to comment.