1use crate::any::TypeId;
5use crate::intrinsics::{self, type_id, type_of};
6use crate::marker::PointeeSized;
7use crate::ptr::DynMetadata;
8
9#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for Type {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field1_finish(f, "Type", "kind",
&&self.kind)
}
}Debug)]
11#[non_exhaustive]
12#[lang = "type_info"]
13#[unstable(feature = "type_info", issue = "146922")]
14pub struct Type {
15 pub kind: TypeKind,
17}
18
19#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl<T: crate::fmt::Debug + PointeeSized> crate::fmt::Debug for TraitImpl<T> {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field1_finish(f, "TraitImpl",
"vtable", &&self.vtable)
}
}Debug, #[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl<T: crate::cmp::PartialEq + PointeeSized> crate::cmp::PartialEq for
TraitImpl<T> {
#[inline]
fn eq(&self, other: &TraitImpl<T>) -> bool { self.vtable == other.vtable }
}PartialEq, #[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl<T: crate::cmp::Eq + PointeeSized> crate::cmp::Eq for TraitImpl<T> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: crate::cmp::AssertParamIsEq<DynMetadata<T>>;
}
}Eq)]
21#[unstable(feature = "type_info", issue = "146922")]
22#[non_exhaustive]
23pub struct TraitImpl<T: PointeeSized> {
24 pub(crate) vtable: DynMetadata<T>,
25}
26
27impl<T: PointeeSized> TraitImpl<T> {
28 pub const fn get_vtable(&self) -> DynMetadata<T> {
30 self.vtable
31 }
32}
33
34impl TypeId {
35 #[unstable(feature = "type_info", issue = "146922")]
38 #[rustc_const_unstable(feature = "type_info", issue = "146922")]
39 pub const fn info(self) -> Type {
40 type_of(self)
41 }
42}
43
44impl Type {
45 #[unstable(feature = "type_info", issue = "146922")]
54 #[rustc_const_unstable(feature = "type_info", issue = "146922")]
55 pub const fn of<T: ?Sized>() -> Self {
56 const { type_id::<T>().info() }
57 }
58}
59
60#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for TypeKind {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
match self {
TypeKind::Tuple(__self_0) =>
crate::fmt::Formatter::debug_tuple_field1_finish(f, "Tuple",
&__self_0),
TypeKind::Array(__self_0) =>
crate::fmt::Formatter::debug_tuple_field1_finish(f, "Array",
&__self_0),
TypeKind::Slice(__self_0) =>
crate::fmt::Formatter::debug_tuple_field1_finish(f, "Slice",
&__self_0),
TypeKind::DynTrait(__self_0) =>
crate::fmt::Formatter::debug_tuple_field1_finish(f,
"DynTrait", &__self_0),
TypeKind::Struct(__self_0) =>
crate::fmt::Formatter::debug_tuple_field1_finish(f, "Struct",
&__self_0),
TypeKind::Enum(__self_0) =>
crate::fmt::Formatter::debug_tuple_field1_finish(f, "Enum",
&__self_0),
TypeKind::Union(__self_0) =>
crate::fmt::Formatter::debug_tuple_field1_finish(f, "Union",
&__self_0),
TypeKind::Bool(__self_0) =>
crate::fmt::Formatter::debug_tuple_field1_finish(f, "Bool",
&__self_0),
TypeKind::Char(__self_0) =>
crate::fmt::Formatter::debug_tuple_field1_finish(f, "Char",
&__self_0),
TypeKind::Int(__self_0) =>
crate::fmt::Formatter::debug_tuple_field1_finish(f, "Int",
&__self_0),
TypeKind::Float(__self_0) =>
crate::fmt::Formatter::debug_tuple_field1_finish(f, "Float",
&__self_0),
TypeKind::Str(__self_0) =>
crate::fmt::Formatter::debug_tuple_field1_finish(f, "Str",
&__self_0),
TypeKind::Reference(__self_0) =>
crate::fmt::Formatter::debug_tuple_field1_finish(f,
"Reference", &__self_0),
TypeKind::Pointer(__self_0) =>
crate::fmt::Formatter::debug_tuple_field1_finish(f, "Pointer",
&__self_0),
TypeKind::FnPtr(__self_0) =>
crate::fmt::Formatter::debug_tuple_field1_finish(f, "FnPtr",
&__self_0),
TypeKind::Other => crate::fmt::Formatter::write_str(f, "Other"),
}
}
}Debug)]
62#[non_exhaustive]
63#[unstable(feature = "type_info", issue = "146922")]
64pub enum TypeKind {
65 Tuple(Tuple),
67 Array(Array),
69 Slice(Slice),
71 DynTrait(DynTrait),
73 Struct(Struct),
75 Enum(Enum),
77 Union(Union),
79 Bool(Bool),
81 Char(Char),
83 Int(Int),
85 Float(Float),
87 Str(Str),
89 Reference(Reference),
91 Pointer(Pointer),
93 FnPtr(FnPtr),
95 Other,
97}
98
99#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for Tuple {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field1_finish(f, "Tuple",
"fields", &&self.fields)
}
}Debug)]
101#[non_exhaustive]
102#[unstable(feature = "type_info", issue = "146922")]
103pub struct Tuple {
104 pub fields: &'static [Field],
106}
107
108#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for Field {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field3_finish(f, "Field", "name",
&self.name, "ty", &self.ty, "offset", &&self.offset)
}
}Debug)]
110#[non_exhaustive]
111#[unstable(feature = "type_info", issue = "146922")]
112pub struct Field {
113 pub name: &'static str,
115 pub ty: TypeId,
117 pub offset: usize,
119}
120
121#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for Array {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field2_finish(f, "Array",
"element_ty", &self.element_ty, "len", &&self.len)
}
}Debug)]
123#[non_exhaustive]
124#[unstable(feature = "type_info", issue = "146922")]
125pub struct Array {
126 pub element_ty: TypeId,
128 pub len: usize,
130}
131
132#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for Slice {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field1_finish(f, "Slice",
"element_ty", &&self.element_ty)
}
}Debug)]
134#[non_exhaustive]
135#[unstable(feature = "type_info", issue = "146922")]
136pub struct Slice {
137 pub element_ty: TypeId,
139}
140
141#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for DynTrait {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field1_finish(f, "DynTrait",
"predicates", &&self.predicates)
}
}Debug)]
144#[non_exhaustive]
145#[unstable(feature = "type_info", issue = "146922")]
146pub struct DynTrait {
147 pub predicates: &'static [DynTraitPredicate],
149}
150
151#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for DynTraitPredicate {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field1_finish(f,
"DynTraitPredicate", "trait_ty", &&self.trait_ty)
}
}Debug)]
153#[non_exhaustive]
154#[unstable(feature = "type_info", issue = "146922")]
155pub struct DynTraitPredicate {
156 pub trait_ty: Trait,
158}
159
160#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for Trait {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field2_finish(f, "Trait", "ty",
&self.ty, "is_auto", &&self.is_auto)
}
}Debug)]
162#[non_exhaustive]
163#[unstable(feature = "type_info", issue = "146922")]
164pub struct Trait {
165 pub ty: TypeId,
167 pub is_auto: bool,
169}
170
171#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for Struct {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field3_finish(f, "Struct",
"generics", &self.generics, "fields", &self.fields,
"non_exhaustive", &&self.non_exhaustive)
}
}Debug)]
173#[non_exhaustive]
174#[unstable(feature = "type_info", issue = "146922")]
175pub struct Struct {
176 pub generics: &'static [Generic],
178 pub fields: &'static [Field],
180 pub non_exhaustive: bool,
182}
183
184#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for Union {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field2_finish(f, "Union",
"generics", &self.generics, "fields", &&self.fields)
}
}Debug)]
186#[non_exhaustive]
187#[unstable(feature = "type_info", issue = "146922")]
188pub struct Union {
189 pub generics: &'static [Generic],
191 pub fields: &'static [Field],
193}
194
195#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for Enum {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field3_finish(f, "Enum",
"generics", &self.generics, "variants", &self.variants,
"non_exhaustive", &&self.non_exhaustive)
}
}Debug)]
197#[non_exhaustive]
198#[unstable(feature = "type_info", issue = "146922")]
199pub struct Enum {
200 pub generics: &'static [Generic],
202 pub variants: &'static [Variant],
204 pub non_exhaustive: bool,
206}
207
208#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for Variant {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field3_finish(f, "Variant",
"name", &self.name, "fields", &self.fields, "non_exhaustive",
&&self.non_exhaustive)
}
}Debug)]
210#[non_exhaustive]
211#[unstable(feature = "type_info", issue = "146922")]
212pub struct Variant {
213 pub name: &'static str,
215 pub fields: &'static [Field],
217 pub non_exhaustive: bool,
219}
220
221#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for Generic {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
match self {
Generic::Lifetime(__self_0) =>
crate::fmt::Formatter::debug_tuple_field1_finish(f,
"Lifetime", &__self_0),
Generic::Type(__self_0) =>
crate::fmt::Formatter::debug_tuple_field1_finish(f, "Type",
&__self_0),
Generic::Const(__self_0) =>
crate::fmt::Formatter::debug_tuple_field1_finish(f, "Const",
&__self_0),
}
}
}Debug)]
223#[non_exhaustive]
224#[unstable(feature = "type_info", issue = "146922")]
225pub enum Generic {
226 Lifetime(Lifetime),
228 Type(GenericType),
230 Const(Const),
232}
233
234#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for Lifetime {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::write_str(f, "Lifetime")
}
}Debug)]
236#[non_exhaustive]
237#[unstable(feature = "type_info", issue = "146922")]
238pub struct Lifetime {
239 }
241
242#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for GenericType {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field1_finish(f, "GenericType",
"ty", &&self.ty)
}
}Debug)]
244#[non_exhaustive]
245#[unstable(feature = "type_info", issue = "146922")]
246pub struct GenericType {
247 pub ty: TypeId,
249}
250
251#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for Const {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field1_finish(f, "Const", "ty",
&&self.ty)
}
}Debug)]
253#[non_exhaustive]
254#[unstable(feature = "type_info", issue = "146922")]
255pub struct Const {
256 pub ty: TypeId,
258}
259
260#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for Bool {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::write_str(f, "Bool")
}
}Debug)]
262#[non_exhaustive]
263#[unstable(feature = "type_info", issue = "146922")]
264pub struct Bool {
265 }
267
268#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for Char {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::write_str(f, "Char")
}
}Debug)]
270#[non_exhaustive]
271#[unstable(feature = "type_info", issue = "146922")]
272pub struct Char {
273 }
275
276#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for Int {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field2_finish(f, "Int", "bits",
&self.bits, "signed", &&self.signed)
}
}Debug)]
278#[non_exhaustive]
279#[unstable(feature = "type_info", issue = "146922")]
280pub struct Int {
281 pub bits: u32,
283 pub signed: bool,
285}
286
287#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for Float {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field1_finish(f, "Float", "bits",
&&self.bits)
}
}Debug)]
289#[non_exhaustive]
290#[unstable(feature = "type_info", issue = "146922")]
291pub struct Float {
292 pub bits: u32,
294}
295
296#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for Str {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::write_str(f, "Str")
}
}Debug)]
298#[non_exhaustive]
299#[unstable(feature = "type_info", issue = "146922")]
300pub struct Str {
301 }
303
304#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for Reference {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field2_finish(f, "Reference",
"pointee", &self.pointee, "mutable", &&self.mutable)
}
}Debug)]
306#[non_exhaustive]
307#[unstable(feature = "type_info", issue = "146922")]
308pub struct Reference {
309 pub pointee: TypeId,
311 pub mutable: bool,
313}
314
315#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for Pointer {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field2_finish(f, "Pointer",
"pointee", &self.pointee, "mutable", &&self.mutable)
}
}Debug)]
317#[non_exhaustive]
318#[unstable(feature = "type_info", issue = "146922")]
319pub struct Pointer {
320 pub pointee: TypeId,
322 pub mutable: bool,
324}
325
326#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for FnPtr {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
crate::fmt::Formatter::debug_struct_field5_finish(f, "FnPtr",
"unsafety", &self.unsafety, "abi", &self.abi, "inputs",
&self.inputs, "output", &self.output, "variadic", &&self.variadic)
}
}Debug)]
327#[unstable(feature = "type_info", issue = "146922")]
328pub struct FnPtr {
330 pub unsafety: bool,
332
333 pub abi: Abi,
335
336 pub inputs: &'static [TypeId],
338
339 pub output: TypeId,
341
342 pub variadic: bool,
344}
345
346#[derive(#[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::fmt::Debug for Abi {
#[inline]
fn fmt(&self, f: &mut crate::fmt::Formatter) -> crate::fmt::Result {
match self {
Abi::Named(__self_0) =>
crate::fmt::Formatter::debug_tuple_field1_finish(f, "Named",
&__self_0),
Abi::ExternRust =>
crate::fmt::Formatter::write_str(f, "ExternRust"),
Abi::ExternC => crate::fmt::Formatter::write_str(f, "ExternC"),
}
}
}Debug, #[automatically_derived]
#[unstable(feature = "type_info", issue = "146922")]
impl crate::default::Default for Abi {
#[inline]
fn default() -> Abi { Self::ExternRust }
}Default)]
347#[non_exhaustive]
348#[unstable(feature = "type_info", issue = "146922")]
349pub enum Abi {
351 Named(&'static str),
353
354 #[default]
356 ExternRust,
357
358 ExternC,
360}
361
362impl TypeId {
363 #[unstable(feature = "type_info", issue = "146922")]
375 #[rustc_const_unstable(feature = "type_info", issue = "146922")]
376 pub const fn size(self) -> Option<usize> {
377 intrinsics::size_of_type_id(self)
378 }
379}