Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clippy_lints/src/zero_sized_map_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ impl LateLintPass<'_> for ZeroSizedMapValues {
// 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()
// Ensure that no region escapes to avoid an assertion error when computing the layout.
// See an example in `issue15429()` of `tests/ui/zero_sized_hashmap_values.rs`.
&& !ty.has_escaping_bound_vars()
&& let Ok(layout) = cx.layout_of(ty)
&& layout.is_zst()
{
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/zero_sized_hashmap_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ fn issue14822() {
//~^ zero_sized_map_values
}

fn issue15429() {
struct E<'a>(&'a [E<'a>]);

// The assertion error happens when the type being evaluated has escaping bound vars
// as it cannot be wrapped in a dummy binder during size computation.
type F = dyn for<'a> FnOnce(HashMap<u32, E<'a>>) -> u32;
}

fn main() {
let _: HashMap<String, ()> = HashMap::new();
//~^ zero_sized_map_values
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/zero_sized_hashmap_values.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,23 @@ LL | type D = HashMap<u32, S<E>>;
= help: consider using a set instead

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

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

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