Skip to content

Commit ea7ebaa

Browse files
authored
Do not attempt to compute size of a type with escaping lifetimes (#15434)
A type with escaping bound vars cannot be wrapped in a dummy binder during size computation. Fixes #15429 changelog: [`zero_sized_hashmap_values`]: fix ICE in types with escaping lifetimes r? Jarcho <!-- TRIAGEBOT_START --> <!-- TRIAGEBOT_SUMMARY_START --> ### Summary Notes - [Beta nomination](#15434 (comment)) by [samueltardieu](https://github.com/samueltardieu) *Managed by `@rustbot`—see [help](https://forge.rust-lang.org/triagebot/note.html) for details* <!-- TRIAGEBOT_SUMMARY_END --> <!-- TRIAGEBOT_END -->
2 parents 388d3f3 + c752fb2 commit ea7ebaa

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

clippy_lints/src/zero_sized_map_values.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ impl LateLintPass<'_> for ZeroSizedMapValues {
5656
// cannot check if it is `Sized` or not, such as an incomplete associated type in a
5757
// type alias. See an example in `issue14822()` of `tests/ui/zero_sized_hashmap_values.rs`.
5858
&& !ty.has_non_region_param()
59+
// Ensure that no region escapes to avoid an assertion error when computing the layout.
60+
// See an example in `issue15429()` of `tests/ui/zero_sized_hashmap_values.rs`.
61+
&& !ty.has_escaping_bound_vars()
5962
&& let Ok(layout) = cx.layout_of(ty)
6063
&& layout.is_zst()
6164
{

tests/ui/zero_sized_hashmap_values.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ fn issue14822() {
9292
//~^ zero_sized_map_values
9393
}
9494

95+
fn issue15429() {
96+
struct E<'a>(&'a [E<'a>]);
97+
98+
// The assertion error happens when the type being evaluated has escaping bound vars
99+
// as it cannot be wrapped in a dummy binder during size computation.
100+
type F = dyn for<'a> FnOnce(HashMap<u32, E<'a>>) -> u32;
101+
}
102+
95103
fn main() {
96104
let _: HashMap<String, ()> = HashMap::new();
97105
//~^ zero_sized_map_values

tests/ui/zero_sized_hashmap_values.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,23 @@ LL | type D = HashMap<u32, S<E>>;
8989
= help: consider using a set instead
9090

9191
error: map with zero-sized value type
92-
--> tests/ui/zero_sized_hashmap_values.rs:96:34
92+
--> tests/ui/zero_sized_hashmap_values.rs:104:34
9393
|
9494
LL | let _: HashMap<String, ()> = HashMap::new();
9595
| ^^^^^^^
9696
|
9797
= help: consider using a set instead
9898

9999
error: map with zero-sized value type
100-
--> tests/ui/zero_sized_hashmap_values.rs:96:12
100+
--> tests/ui/zero_sized_hashmap_values.rs:104:12
101101
|
102102
LL | let _: HashMap<String, ()> = HashMap::new();
103103
| ^^^^^^^^^^^^^^^^^^^
104104
|
105105
= help: consider using a set instead
106106

107107
error: map with zero-sized value type
108-
--> tests/ui/zero_sized_hashmap_values.rs:102:12
108+
--> tests/ui/zero_sized_hashmap_values.rs:110:12
109109
|
110110
LL | let _: HashMap<_, _> = std::iter::empty::<(String, ())>().collect();
111111
| ^^^^^^^^^^^^^

0 commit comments

Comments
 (0)