Skip to content

large_enum_variant false positive (incorrect size calculation?) #9798

Closed
@djc

Description

@djc

Summary

There seems to be a regression in calculating the size for the type contained in a variant here.

https://github.com/tokio-rs/tls/actions/runs/3391306304/jobs/5636351880

Lint Name

large_enum_variant

Reproducer

I tried this code:

pub enum TlsStream<T> {
    Client(client::TlsStream<T>),
    Server(server::TlsStream<T>),
}

I saw this happen:

Error:    --> tokio-rustls/src/lib.rs:393:1
    |
393 | / pub enum TlsStream<T> {
394 | |     Client(client::TlsStream<T>),
    | |     ---------------------------- the second-largest variant contains at least 0 bytes
395 | |     Server(server::TlsStream<T>),
    | |     ---------------------------- the largest variant contains at least 608 bytes
396 | | }
    | |_^ the entire enum is at least 0 bytes
    |
    = note: `-D clippy::large-enum-variant` implied by `-D warnings`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant
help: consider boxing the large fields to reduce the total size of the enum
    |
395 |     Server(Box<server::TlsStream<T>>),
    |            ~~~~~~~~~~~~~~~~~~~~~~~~~

I expected to see this happen:

Smaller size difference, or maybe no lint at all.

Version

rustc 1.65.0 (897e37553 2022-11-02)
binary: rustc
commit-hash: 897e37553bba8b42751c67658967889d11ecd120
commit-date: 2022-11-02
host: aarch64-apple-darwin
release: 1.65.0
LLVM version: 15.0.0

Additional Labels

Seems to be a regression in 1.65.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions