Skip to content

Commit 38d8903

Browse files
committed
Remove is_normalizable. layout_of no longer contains a delay_bug.
1 parent 549107d commit 38d8903

File tree

4 files changed

+7
-68
lines changed

4 files changed

+7
-68
lines changed

clippy_lints/src/casts/manual_dangling_ptr.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::SpanRangeExt;
3-
use clippy_utils::ty::is_normalizable;
43
use clippy_utils::{expr_or_init, match_def_path, path_def_id, paths, std_or_core};
54
use rustc_ast::LitKind;
65
use rustc_errors::Applicability;
@@ -71,12 +70,10 @@ fn is_literal_aligned(cx: &LateContext<'_>, lit: &Spanned<LitKind>, to: &Ty<'_>)
7170
return false;
7271
}
7372
let to_mid_ty = cx.typeck_results().node_type(to.hir_id);
74-
is_normalizable(cx, cx.param_env, to_mid_ty)
75-
&& cx
76-
.tcx
77-
.layout_of(cx.typing_env().as_query_input(to_mid_ty))
78-
.is_ok_and(|layout| {
79-
let align = u128::from(layout.align.abi.bytes());
80-
u128::from(val) <= align
81-
})
73+
cx.tcx
74+
.layout_of(cx.typing_env().as_query_input(to_mid_ty))
75+
.is_ok_and(|layout| {
76+
let align = u128::from(layout.align.abi.bytes());
77+
u128::from(val) <= align
78+
})
8279
}

clippy_lints/src/transmute/eager_transmute.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
2-
use clippy_utils::ty::is_normalizable;
32
use clippy_utils::{eq_expr_value, path_to_local, sym};
43
use rustc_abi::WrappingRange;
54
use rustc_errors::Applicability;
@@ -84,8 +83,6 @@ pub(super) fn check<'tcx>(
8483
&& path.ident.name == sym::then_some
8584
&& is_local_with_projections(transmutable)
8685
&& binops_with_local(cx, transmutable, receiver)
87-
&& is_normalizable(cx, cx.param_env, from_ty)
88-
&& is_normalizable(cx, cx.param_env, to_ty)
8986
// we only want to lint if the target type has a niche that is larger than the one of the source type
9087
// e.g. `u8` to `NonZero<u8>` should lint, but `NonZero<u8>` to `u8` should not
9188
&& let Ok(from_layout) = cx.tcx.layout_of(cx.typing_env().as_query_input(from_ty))

clippy_lints/src/zero_sized_map_values.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
2-
use clippy_utils::ty::{is_normalizable, is_type_diagnostic_item, ty_from_hir_ty};
2+
use clippy_utils::ty::{is_type_diagnostic_item, ty_from_hir_ty};
33
use rustc_hir::{self as hir, AmbigArg, HirId, ItemKind, Node};
44
use rustc_lint::{LateContext, LateLintPass};
55
use rustc_middle::ty::layout::LayoutOf as _;
@@ -54,8 +54,6 @@ impl LateLintPass<'_> for ZeroSizedMapValues {
5454
// Fixes https://github.com/rust-lang/rust-clippy/issues/7447 because of
5555
// https://github.com/rust-lang/rust/blob/master/compiler/rustc_middle/src/ty/sty.rs#L968
5656
&& !ty.has_escaping_bound_vars()
57-
// Do this to prevent `layout_of` crashing, being unable to fully normalize `ty`.
58-
&& is_normalizable(cx, cx.param_env, ty)
5957
&& let Ok(layout) = cx.layout_of(ty)
6058
&& layout.is_zst()
6159
{

clippy_utils/src/ty/mod.rs

-53
Original file line numberDiff line numberDiff line change
@@ -359,56 +359,6 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
359359
}
360360
}
361361

362-
// FIXME: Per https://doc.rust-lang.org/nightly/nightly-rustc/rustc_trait_selection/infer/at/struct.At.html#method.normalize
363-
// this function can be removed once the `normalize` method does not panic when normalization does
364-
// not succeed
365-
/// Checks if `Ty` is normalizable. This function is useful
366-
/// to avoid crashes on `layout_of`.
367-
pub fn is_normalizable<'tcx>(cx: &LateContext<'tcx>, param_env: ParamEnv<'tcx>, ty: Ty<'tcx>) -> bool {
368-
is_normalizable_helper(cx, param_env, ty, 0, &mut FxHashMap::default())
369-
}
370-
371-
fn is_normalizable_helper<'tcx>(
372-
cx: &LateContext<'tcx>,
373-
param_env: ParamEnv<'tcx>,
374-
ty: Ty<'tcx>,
375-
depth: usize,
376-
cache: &mut FxHashMap<Ty<'tcx>, bool>,
377-
) -> bool {
378-
if let Some(&cached_result) = cache.get(&ty) {
379-
return cached_result;
380-
}
381-
if !cx.tcx.recursion_limit().value_within_limit(depth) {
382-
return false;
383-
}
384-
// Prevent recursive loops by answering `true` to recursive requests with the same
385-
// type. This will be adjusted when the outermost call analyzes all the type
386-
// components.
387-
cache.insert(ty, true);
388-
let infcx = cx.tcx.infer_ctxt().build(cx.typing_mode());
389-
let cause = ObligationCause::dummy();
390-
let result = if infcx.at(&cause, param_env).query_normalize(ty).is_ok() {
391-
match ty.kind() {
392-
ty::Adt(def, args) => def.variants().iter().all(|variant| {
393-
variant
394-
.fields
395-
.iter()
396-
.all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, args), depth + 1, cache))
397-
}),
398-
_ => ty.walk().all(|generic_arg| match generic_arg.unpack() {
399-
GenericArgKind::Type(inner_ty) if inner_ty != ty => {
400-
is_normalizable_helper(cx, param_env, inner_ty, depth + 1, cache)
401-
},
402-
_ => true, // if inner_ty == ty, we've already checked it
403-
}),
404-
}
405-
} else {
406-
false
407-
};
408-
cache.insert(ty, result);
409-
result
410-
}
411-
412362
/// Returns `true` if the given type is a non aggregate primitive (a `bool` or `char`, any
413363
/// integer or floating-point number type).
414364
///
@@ -993,9 +943,6 @@ pub fn adt_and_variant_of_res<'tcx>(cx: &LateContext<'tcx>, res: Res) -> Option<
993943
/// account the layout of type parameters.
994944
pub fn approx_ty_size<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> u64 {
995945
use rustc_middle::ty::layout::LayoutOf;
996-
if !is_normalizable(cx, cx.param_env, ty) {
997-
return 0;
998-
}
999946
match (cx.layout_of(ty).map(|layout| layout.size.bytes()), ty.kind()) {
1000947
(Ok(size), _) => size,
1001948
(Err(_), ty::Tuple(list)) => list.iter().map(|t| approx_ty_size(cx, t)).sum(),

0 commit comments

Comments
 (0)