Closed
Description
The following code:
#![feature(const_generics)]
trait IsZst {
type ZST;
}
impl<T: Sized> IsZst for T where T: Sized {
type ZST = ZstHelper<{std::mem::size_of::<T>() == 0}>;
}
struct ZstHelper<const T: bool>;
produces the following error:
error[E0277]: the size for values of type `T` cannot be known at compilation time
--> src/lib.rs:8:27
|
8 | type ZST = ZstHelper<{std::mem::size_of::<T>() == 0}>;
| ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `std::marker::Sized` is not implemented for `T`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
= help: consider adding a `where T: std::marker::Sized` bound
= note: required by `std::mem::size_of`
despite the fact that we have that T: Sized
. If there's another reason why this code shouldn't compile, the error message should clearly state it.
Metadata
Metadata
Assignees
Labels
Area: const generics (parameters and arguments)Area: Messages for errors, warnings, and lintsCategory: This is a bug.`#![feature(const_generics)]`Error messages that can be tackled with `#[rustc_on_unimplemented]`Relevant to the compiler team, which will review and decide on the PR/issue.This issue requires a nightly compiler in some way.