Skip to content

Commit f922812

Browse files
committed
Fix ICE due to normalization failure
1 parent d9e38f5 commit f922812

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

clippy_lints/src/transmute.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,18 @@ fn get_type_snippet(cx: &LateContext<'_, '_>, path: &QPath<'_>, to_ref_ty: Ty<'_
639639
// check if the component types of the transmuted collection and the result have different ABI,
640640
// size or alignment
641641
fn is_layout_incompatible<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, from: Ty<'tcx>, to: Ty<'tcx>) -> bool {
642-
let from_ty_layout = cx.tcx.layout_of(ty::ParamEnv::empty().and(from));
643-
let to_ty_layout = cx.tcx.layout_of(ty::ParamEnv::empty().and(to));
642+
let empty_param_env = ty::ParamEnv::empty();
643+
// check if `from` and `to` are normalizable to avoid ICE (#4968)
644+
let is_normalizable = cx.tcx.infer_ctxt().enter(|infcx| {
645+
let cause = rustc::traits::ObligationCause::dummy();
646+
infcx.at(&cause, empty_param_env).normalize(&from).is_ok()
647+
&& infcx.at(&cause, empty_param_env).normalize(&to).is_ok()
648+
});
649+
if !is_normalizable {
650+
return false;
651+
}
652+
let from_ty_layout = cx.tcx.layout_of(empty_param_env.and(from));
653+
let to_ty_layout = cx.tcx.layout_of(empty_param_env.and(to));
644654
if let (Ok(from_layout), Ok(to_layout)) = (from_ty_layout, to_ty_layout) {
645655
from_layout.size != to_layout.size || from_layout.align != to_layout.align || from_layout.abi != to_layout.abi
646656
} else {

0 commit comments

Comments
 (0)