|
1 | 1 | use clippy_utils::last_path_segment;
|
2 | 2 | use clippy_utils::source::snippet;
|
3 |
| -use clippy_utils::ty::is_normalizable; |
4 | 3 | use if_chain::if_chain;
|
5 | 4 | use rustc_hir::{Expr, GenericArg, QPath, TyKind};
|
6 | 5 | use rustc_lint::LateContext;
|
7 |
| -use rustc_middle::ty::{self, cast::CastKind, Ty}; |
| 6 | +use rustc_middle::ty::{cast::CastKind, Ty}; |
8 | 7 | use rustc_span::DUMMY_SP;
|
9 | 8 | use rustc_typeck::check::{cast::CastCheck, FnCtxt, Inherited};
|
10 | 9 |
|
@@ -34,15 +33,12 @@ pub(super) fn get_type_snippet(cx: &LateContext<'_>, path: &QPath<'_>, to_ref_ty
|
34 | 33 | // check if the component types of the transmuted collection and the result have different ABI,
|
35 | 34 | // size or alignment
|
36 | 35 | pub(super) fn is_layout_incompatible<'tcx>(cx: &LateContext<'tcx>, from: Ty<'tcx>, to: Ty<'tcx>) -> bool {
|
37 |
| - let empty_param_env = ty::ParamEnv::empty(); |
38 |
| - // check if `from` and `to` are normalizable to avoid ICE (#4968) |
39 |
| - if !(is_normalizable(cx, empty_param_env, from) && is_normalizable(cx, empty_param_env, to)) { |
40 |
| - return false; |
41 |
| - } |
42 |
| - let from_ty_layout = cx.tcx.layout_of(empty_param_env.and(from)); |
43 |
| - let to_ty_layout = cx.tcx.layout_of(empty_param_env.and(to)); |
44 |
| - if let (Ok(from_layout), Ok(to_layout)) = (from_ty_layout, to_ty_layout) { |
45 |
| - from_layout.size != to_layout.size || from_layout.align != to_layout.align || from_layout.abi != to_layout.abi |
| 36 | + if let Ok(from) = cx.tcx.try_normalize_erasing_regions(cx.param_env, from) |
| 37 | + && let Ok(to) = cx.tcx.try_normalize_erasing_regions(cx.param_env, to) |
| 38 | + && let Ok(from_layout) = cx.tcx.layout_of(cx.param_env.and(from)) |
| 39 | + && let Ok(to_layout) = cx.tcx.layout_of(cx.param_env.and(to)) |
| 40 | + { |
| 41 | + from_layout.size != to_layout.size || from_layout.align.abi != to_layout.align.abi |
46 | 42 | } else {
|
47 | 43 | // no idea about layout, so don't lint
|
48 | 44 | false
|
|
0 commit comments