Skip to content

Confused by the error message #49964

Closed
Closed
@juchiast

Description

@juchiast

I'm trying to write this code:

fn binary_dump<T: Sized>(f: T) -> String {
    let v = [0u8; std::mem::size_of::<T>()];
    String::new()
}

rustc gives this error message:

error[E0277]: the trait bound `T: std::marker::Sized` is not satisfied
 --> src/main.rs:2:19
  |
2 |     let v = [0u8; std::mem::size_of::<T>()];
  |                   ^^^^^^^^^^^^^^^^^^^^^^ `T` does not have a constant size known at compile-time
  |
  = help: the trait `std::marker::Sized` is not implemented for `T`
  = help: consider adding a `where T: std::marker::Sized` bound
  = note: required by `std::mem::size_of`

This is confusing because T already have Sized.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions