Skip to content

Commit 7118d37

Browse files
committed
Auto merge of #6154 - flip1995:ice_fixes, r=ebroto
Fix two ICEs caused by ty.is_{sized,freeze} Fixes #6153 Properly fixes #6139 The test case in #6153 is kind of weird. Even removing one of the arguments of the `foo` function prevented the ICE. I think this test case is actually minimal. changelog: none
2 parents 8b70b84 + 52e650a commit 7118d37

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

clippy_lints/src/mut_key.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::utils::{match_def_path, paths, span_lint, trait_ref_of_method};
22
use rustc_hir as hir;
33
use rustc_lint::{LateContext, LateLintPass};
4+
use rustc_middle::ty::TypeFoldable;
45
use rustc_middle::ty::{Adt, Array, RawPtr, Ref, Slice, Tuple, Ty, TypeAndMut};
56
use rustc_session::{declare_lint_pass, declare_tool_lint};
67
use rustc_span::source_map::Span;
@@ -120,7 +121,11 @@ fn is_mutable_type<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span) -> bo
120121
size.try_eval_usize(cx.tcx, cx.param_env).map_or(true, |u| u != 0) && is_mutable_type(cx, inner_ty, span)
121122
},
122123
Tuple(..) => ty.tuple_fields().any(|ty| is_mutable_type(cx, ty, span)),
123-
Adt(..) => cx.tcx.layout_of(cx.param_env.and(ty)).is_ok() && !ty.is_freeze(cx.tcx.at(span), cx.param_env),
124+
Adt(..) => {
125+
cx.tcx.layout_of(cx.param_env.and(ty)).is_ok()
126+
&& !ty.has_escaping_bound_vars()
127+
&& !ty.is_freeze(cx.tcx.at(span), cx.param_env)
128+
},
124129
_ => false,
125130
}
126131
}

clippy_lints/src/types.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_hir::{
1717
use rustc_lint::{LateContext, LateLintPass, LintContext};
1818
use rustc_middle::hir::map::Map;
1919
use rustc_middle::lint::in_external_macro;
20+
use rustc_middle::ty::TypeFoldable;
2021
use rustc_middle::ty::{self, InferTy, Ty, TyCtxt, TyS, TypeckResults};
2122
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
2223
use rustc_span::hygiene::{ExpnKind, MacroKind};
@@ -541,11 +542,7 @@ impl Types {
541542
_ => None,
542543
});
543544
let ty_ty = hir_ty_to_ty(cx.tcx, boxed_ty);
544-
// HACK(flip1995): This is a fix for an ICE occuring when `ty_ty` is a
545-
// trait object with a lifetime, e.g. `dyn T<'_>`. Since trait objects
546-
// don't have a known size, this shouldn't introduce FNs. But there
547-
// should be a better solution.
548-
if !matches!(ty_ty.kind(), ty::Dynamic(..));
545+
if !ty_ty.has_escaping_bound_vars();
549546
if ty_ty.is_sized(cx.tcx.at(ty.span), cx.param_env);
550547
if let Ok(ty_ty_size) = cx.layout_of(ty_ty).map(|l| l.size.bytes());
551548
if ty_ty_size <= self.vec_box_size_threshold;

tests/ui/crashes/ice-6153.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pub struct S<'a, 'e>(&'a str, &'e str);
2+
3+
pub type T<'a, 'e> = std::collections::HashMap<S<'a, 'e>, ()>;
4+
5+
impl<'e, 'a: 'e> S<'a, 'e> {
6+
pub fn foo(_a: &str, _b: &str, _map: &T) {}
7+
}
8+
9+
fn main() {}

0 commit comments

Comments
 (0)