Skip to content

Commit 8d7f638

Browse files
committed
Auto merge of #9773 - Alexendoo:ice-9746, r=Manishearth
Fix ICE in `redundant_allocation` changelog: Fix ICE in `redundant_allocation` Closes #9746, the original issue was fixed already, this gets the one in #9746 (comment)
2 parents 647644b + 517605e commit 8d7f638

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

clippy_lints/src/types/redundant_allocation.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_errors::Applicability;
55
use rustc_hir::{self as hir, def_id::DefId, QPath, TyKind};
66
use rustc_hir_analysis::hir_ty_to_ty;
77
use rustc_lint::LateContext;
8+
use rustc_middle::ty::TypeVisitable;
89
use rustc_span::symbol::sym;
910

1011
use super::{utils, REDUNDANT_ALLOCATION};
@@ -51,14 +52,15 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_
5152
return false
5253
};
5354
let inner_span = match qpath_generic_tys(inner_qpath).next() {
54-
Some(ty) => {
55+
Some(hir_ty) => {
5556
// Reallocation of a fat pointer causes it to become thin. `hir_ty_to_ty` is safe to use
5657
// here because `mod.rs` guarantees this lint is only run on types outside of bodies and
5758
// is not run on locals.
58-
if !hir_ty_to_ty(cx.tcx, ty).is_sized(cx.tcx.at(ty.span), cx.param_env) {
59+
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
60+
if ty.has_escaping_bound_vars() || !ty.is_sized(cx.tcx.at(hir_ty.span), cx.param_env) {
5961
return false;
6062
}
61-
ty.span
63+
hir_ty.span
6264
},
6365
None => return false,
6466
};

tests/ui/crashes/ice-9746.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//! <https://github.com/rust-lang/rust-clippy/issues/9746#issuecomment-1297132880>
2+
3+
trait Trait {}
4+
5+
struct Struct<'a> {
6+
_inner: &'a Struct<'a>,
7+
}
8+
9+
impl Trait for Struct<'_> {}
10+
11+
fn example<'a>(s: &'a Struct) -> Box<Box<dyn Trait + 'a>> {
12+
Box::new(Box::new(Struct { _inner: s }))
13+
}
14+
15+
fn main() {}

0 commit comments

Comments
 (0)