-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Open
Labels
A-type-systemArea: Type systemArea: Type systemC-bugCategory: This is a bug.Category: This is a bug.F-type_info#![feature(type_info)]#![feature(type_info)]T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
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.
Metadata
Metadata
Assignees
Labels
A-type-systemArea: Type systemArea: Type systemC-bugCategory: This is a bug.Category: This is a bug.F-type_info#![feature(type_info)]#![feature(type_info)]T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.