Skip to content

Add an assert_size attribute for structs #18161

@kmcallister

Description

@kmcallister

size_of is maybe the top use case for function evaluation in static asserts, which doesn't seem like it will happen any time soon. We can satisfy this use case with a very simple and self-contained feature, e.g.

#[assert_size(48)]
struct StringCacheEntry {
    next_in_bucket: *mut StringCacheEntry,
    hash: u64,
    ref_count: AtomicInt,
    string: String,
}

I think making this kind of assertion painless will help programs avoid performance regressions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions