diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2025-05-18 14:39:28 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2025-05-20 01:21:22 +0200 |
| commit | 72a4e33d69d982c6d26d19d65e136f21bded3184 (patch) | |
| tree | 5bc5a8e068eee36eae8829b521da0a8355774331 /clippy_lints | |
| parent | da7b678992dd65dbd644bfe30ba61a9a0d2c695c (diff) | |
| download | rust-72a4e33d69d982c6d26d19d65e136f21bded3184.tar.gz rust-72a4e33d69d982c6d26d19d65e136f21bded3184.zip | |
Fix ICE while computing type layout
If a type is incomplete, for example if generic parameters are not available yet, although they are not escaping, its layout may not be computable. Calling `TyCtxt::layout_of()` would create a delayed bug in the compiler.
Diffstat (limited to 'clippy_lints')
| -rw-r--r-- | clippy_lints/src/zero_sized_map_values.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs index 24b1381ba45..1550872bca2 100644 --- a/clippy_lints/src/zero_sized_map_values.rs +++ b/clippy_lints/src/zero_sized_map_values.rs @@ -51,9 +51,11 @@ impl LateLintPass<'_> for ZeroSizedMapValues { && (is_type_diagnostic_item(cx, ty, sym::HashMap) || is_type_diagnostic_item(cx, ty, sym::BTreeMap)) && let ty::Adt(_, args) = ty.kind() && let ty = args.type_at(1) - // Fixes https://github.com/rust-lang/rust-clippy/issues/7447 because of - // https://github.com/rust-lang/rust/blob/master/compiler/rustc_middle/src/ty/sty.rs#L968 - && !ty.has_escaping_bound_vars() + // Ensure that no type information is missing, to avoid a delayed bug in the compiler if this is not the case. + // This might happen when computing a reference/pointer metadata on a type for which we + // cannot check if it is `Sized` or not, such as an incomplete associated type in a + // type alias. See an example in `issue14822()` of `tests/ui/zero_sized_hashmap_values.rs`. + && !ty.has_non_region_param() && let Ok(layout) = cx.layout_of(ty) && layout.is_zst() { |
