Skip to content

Incorrect error message: type parameter needs to be Sized, despite explicit bound #74149

Closed
@e2-71828

Description

@e2-71828

For the code below, the compiler complains that Item needs to be Sized, despite that being an explicitly-stated bound.

const PAGE_SIZE:usize=4096;

#[repr(align(4096))]
struct Page<Item: std::marker::Sized> {
    arr: [Item; PAGE_SIZE/std::mem::size_of::<Item>()],
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0277]: the size for values of type `Item` cannot be known at compilation time
   --> src/lib.rs:5:47
    |
4   | struct Page<Item: std::marker::Sized> {
    |             ---- this type parameter needs to be `std::marker::Sized`
5   |     arr: [Item; PAGE_SIZE/std::mem::size_of::<Item>()],
    |                                               ^^^^ doesn't have a size known at compile-time
    |
    = help: the trait `std::marker::Sized` is not implemented for `Item`
    = note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground`.

To learn more, run the command again with --verbose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-lazy-normalizationArea: Lazy normalization (tracking issue: #60471)D-confusingDiagnostics: Confusing error or lint that should be reworked.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions