diff options
| author | Jason Newcomb <jsnewcomb@pm.me> | 2025-05-19 23:33:39 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-19 23:33:39 +0000 |
| commit | 6753e164be65dbb24f6a5b43b65e08772a313d2d (patch) | |
| tree | 77ac74a481c84d414d3a5e78d4f7b5c27a7b09e0 /clippy_lints | |
| parent | 66697e84b19c117b308eb1c02edcd6e6f299e30d (diff) | |
| parent | 72a4e33d69d982c6d26d19d65e136f21bded3184 (diff) | |
| download | rust-6753e164be65dbb24f6a5b43b65e08772a313d2d.tar.gz rust-6753e164be65dbb24f6a5b43b65e08772a313d2d.zip | |
Fix ICE while computing type layout (#14837)
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. changelog: [`zero_sized_map_values`]: fix ICE Fixes rust-lang/rust-clippy#14822 r? @Jarcho
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() { |
