Closed
Description
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>()],
}
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.