I tried this code:
#![feature(type_info)]
use std::mem::type_info::Type;
fn main() {
let type_ = const { Type::of::<str>() };
}
I expected this to compile successfully.
Instead, I received an error that Type::of doesn't support unsized types:
error[E0277]: the size for values of type `str` cannot be known at compilation time
--> ~/dev/rust-lang/rust/tests/ui/reflection/size.rs:11:37
|
LL | let _type_ = const { Type::of::<str>() };
| ^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `str`
note: required by an implicit `Sized` bound in `Type::of`
I believe this occurs because Type::of doesn't have an ?Sized bound. As a temporary workaround, I used TypeId::of first, and then accessed the info from there:
let type_ = const { TypeId::of::<str>().info() };
Meta
This is on the main branch (commit 1377169). This uses the type_info feature (#146922), and is related to #146923.
I tried this code:
I expected this to compile successfully.
Instead, I received an error that
Type::ofdoesn't support unsized types:I believe this occurs because
Type::ofdoesn't have an?Sizedbound. As a temporary workaround, I usedTypeId::offirst, and then accessed the info from there:Meta
This is on the
mainbranch (commit 1377169). This uses thetype_infofeature (#146922), and is related to #146923.