1use serde::Serialize;
2
3use crate::abi::ReprOptions;
4use crate::crate_def::{CrateDef, CrateDefType};
5use crate::mir::Body;
6use crate::ty::tys::*;
7use crate::{AssocItems, DefId, IndexedVal, Symbol, with};
8
9#[automatically_derived]
impl ::core::clone::Clone for AssocDef {
#[inline]
fn clone(&self) -> AssocDef {
let _: ::core::clone::AssertParamIsClone<DefId>;
*self
}
}
#[automatically_derived]
impl ::core::marker::Copy for AssocDef { }
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for AssocDef { }
#[automatically_derived]
impl ::core::cmp::PartialEq for AssocDef {
#[inline]
fn eq(&self, other: &AssocDef) -> bool { self.0 == other.0 }
}
#[automatically_derived]
impl ::core::cmp::Eq for AssocDef {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<DefId>;
}
}
#[automatically_derived]
impl ::core::fmt::Debug for AssocDef {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "AssocDef",
&&self.0)
}
}
#[automatically_derived]
impl ::core::hash::Hash for AssocDef {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}
#[doc(hidden)]
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications,
clippy :: absolute_paths,)]
const _: () =
{
#[allow(unused_extern_crates, clippy :: useless_attribute)]
extern crate serde as _serde;
;
#[automatically_derived]
impl _serde::Serialize for AssocDef {
fn serialize<__S>(&self, __serializer: __S)
-> _serde::__private228::Result<__S::Ok, __S::Error> where
__S: _serde::Serializer {
_serde::Serializer::serialize_newtype_struct(__serializer,
"AssocDef", &self.0)
}
}
};
impl CrateDef for AssocDef {
fn def_id(&self) -> DefId { self.0 }
}crate_def! {
10 #[derive(Serialize)]
11 pub ForeignModuleDef;
12
13 #[derive(Serialize)]
14 pub ClosureDef;
15
16 #[derive(Serialize)]
17 pub CoroutineDef;
18
19 #[derive(Serialize)]
20 pub CoroutineClosureDef;
21
22 #[derive(Serialize)]
23 pub ParamDef;
24
25 #[derive(Serialize)]
26 pub BrNamedDef;
27
28 #[derive(Serialize)]
29 pub AdtDef;
30
31 #[derive(Serialize)]
32 pub AliasDef;
33
34 #[derive(Serialize)]
36 pub TraitDef;
37
38 #[derive(Serialize)]
39 pub GenericDef;
40
41 #[derive(Serialize)]
42 pub RegionDef;
43
44 #[derive(Serialize)]
45 pub CoroutineWitnessDef;
46
47 #[derive(Serialize)]
49 pub OpaqueDef;
50
51 #[derive(Serialize)]
52 pub AssocDef;
53}
54
55#[automatically_derived]
impl ::core::clone::Clone for ImplDef {
#[inline]
fn clone(&self) -> ImplDef {
let _: ::core::clone::AssertParamIsClone<DefId>;
*self
}
}
#[automatically_derived]
impl ::core::marker::Copy for ImplDef { }
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for ImplDef { }
#[automatically_derived]
impl ::core::cmp::PartialEq for ImplDef {
#[inline]
fn eq(&self, other: &ImplDef) -> bool { self.0 == other.0 }
}
#[automatically_derived]
impl ::core::cmp::Eq for ImplDef {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<DefId>;
}
}
#[automatically_derived]
impl ::core::fmt::Debug for ImplDef {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "ImplDef",
&&self.0)
}
}
#[automatically_derived]
impl ::core::hash::Hash for ImplDef {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.0, state)
}
}
#[doc(hidden)]
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications,
clippy :: absolute_paths,)]
const _: () =
{
#[allow(unused_extern_crates, clippy :: useless_attribute)]
extern crate serde as _serde;
;
#[automatically_derived]
impl _serde::Serialize for ImplDef {
fn serialize<__S>(&self, __serializer: __S)
-> _serde::__private228::Result<__S::Ok, __S::Error> where
__S: _serde::Serializer {
_serde::Serializer::serialize_newtype_struct(__serializer,
"ImplDef", &self.0)
}
}
};
impl CrateDef for ImplDef {
fn def_id(&self) -> DefId { self.0 }
}
impl CrateDefType for ImplDef {}crate_def_with_ty! {
56 #[derive(Serialize)]
58 pub ForeignDef;
59
60 #[derive(Serialize)]
62 pub FnDef;
63
64 #[derive(Serialize)]
65 pub IntrinsicDef;
66
67 #[derive(Serialize)]
68 pub FieldDef {
69 pub name: Symbol,
71 }
72
73 #[derive(Serialize)]
74 pub ConstDef;
75
76 #[derive(Serialize)]
78 pub ImplDef;
79}
80
81impl ForeignModuleDef {
82 pub fn module(&self) -> ForeignModule {
83 with(|cx| cx.foreign_module(*self))
84 }
85}
86
87impl ForeignDef {
88 pub fn kind(&self) -> ForeignItemKind {
89 with(|cx| cx.foreign_item_kind(*self))
90 }
91}
92
93impl FnDef {
94 pub fn body(&self) -> Option<Body> {
96 with(|ctx| ctx.has_body(self.0).then(|| ctx.mir_body(self.0)))
97 }
98
99 pub fn has_body(&self) -> bool {
101 with(|ctx| ctx.has_body(self.0))
102 }
103
104 pub fn as_intrinsic(&self) -> Option<IntrinsicDef> {
106 with(|cx| cx.intrinsic(self.def_id()))
107 }
108
109 #[inline]
111 pub fn is_intrinsic(&self) -> bool {
112 self.as_intrinsic().is_some()
113 }
114
115 pub fn constness(&self) -> Constness {
117 with(|cx| cx.constness(*self))
118 }
119
120 pub fn asyncness(&self) -> Asyncness {
122 with(|cx| cx.asyncness(*self))
123 }
124
125 pub fn fn_sig(&self) -> PolyFnSig {
127 let kind = self.ty().kind();
128 kind.fn_sig().unwrap()
129 }
130
131 pub fn generics_of(&self) -> Generics {
133 with(|cx| cx.generics_of(self.0))
134 }
135
136 pub fn associated_item(&self) -> Option<AssocItem> {
138 with(|cx| cx.associated_item(self.0))
139 }
140}
141
142impl IntrinsicDef {
143 pub fn fn_name(&self) -> Symbol {
146 with(|cx| cx.intrinsic_name(*self))
147 }
148
149 pub fn must_be_overridden(&self) -> bool {
152 with(|cx| !cx.has_body(self.0))
153 }
154}
155
156impl From<IntrinsicDef> for FnDef {
157 fn from(def: IntrinsicDef) -> Self {
158 FnDef(def.0)
159 }
160}
161
162impl ClosureDef {
163 pub fn body(&self) -> Option<Body> {
166 with(|ctx| ctx.has_body(self.0).then(|| ctx.mir_body(self.0)))
167 }
168}
169
170impl CoroutineDef {
171 pub fn body(&self) -> Option<Body> {
174 with(|cx| cx.has_body(self.0).then(|| cx.mir_body(self.0)))
175 }
176
177 pub fn discriminant_for_variant(&self, args: &GenericArgs, idx: VariantIdx) -> Discr {
178 with(|cx| cx.coroutine_discr_for_variant(*self, args, idx))
179 }
180}
181
182impl AdtDef {
183 pub fn kind(&self) -> AdtKind {
184 with(|cx| cx.adt_kind(*self))
185 }
186
187 pub fn ty(&self) -> Ty {
189 with(|cx| cx.def_ty(self.0))
190 }
191
192 pub fn ty_with_args(&self, args: &GenericArgs) -> Ty {
196 with(|cx| cx.def_ty_with_args(self.0, args))
197 }
198
199 pub fn is_box(&self) -> bool {
200 with(|cx| cx.adt_is_box(*self))
201 }
202
203 pub fn is_simd(&self) -> bool {
204 with(|cx| cx.adt_is_simd(*self))
205 }
206
207 pub fn num_variants(&self) -> usize {
209 with(|cx| cx.adt_variants_len(*self))
210 }
211
212 pub fn variants(&self) -> Vec<VariantDef> {
214 self.variants_iter().collect()
215 }
216
217 pub fn variants_iter(&self) -> impl Iterator<Item = VariantDef> {
219 (0..self.num_variants())
220 .map(|idx| VariantDef { idx: VariantIdx::to_val(idx), adt_def: *self })
221 }
222
223 pub fn variant(&self, idx: VariantIdx) -> Option<VariantDef> {
224 (idx.to_index() < self.num_variants()).then_some(VariantDef { idx, adt_def: *self })
225 }
226
227 pub fn repr(&self) -> ReprOptions {
228 with(|cx| cx.adt_repr(*self))
229 }
230
231 pub fn discriminant_for_variant(&self, idx: VariantIdx) -> Discr {
232 with(|cx| cx.adt_discr_for_variant(*self, idx))
233 }
234
235 pub fn generics_of(&self) -> Generics {
237 with(|cx| cx.generics_of(self.0))
238 }
239
240 pub fn inherent_impls(&self) -> Vec<ImplDef> {
242 with(|cx| cx.inherent_impls(*self))
243 }
244}
245
246#[derive(#[automatically_derived]
impl ::core::clone::Clone for VariantDef {
#[inline]
fn clone(&self) -> VariantDef {
let _: ::core::clone::AssertParamIsClone<VariantIdx>;
let _: ::core::clone::AssertParamIsClone<AdtDef>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for VariantDef { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for VariantDef {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "VariantDef",
"idx", &self.idx, "adt_def", &&self.adt_def)
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for VariantDef {
#[inline]
fn eq(&self, other: &VariantDef) -> bool {
self.idx == other.idx && self.adt_def == other.adt_def
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for VariantDef {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<VariantIdx>;
let _: ::core::cmp::AssertParamIsEq<AdtDef>;
}
}Eq, #[automatically_derived]
impl ::core::hash::Hash for VariantDef {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.idx, state);
::core::hash::Hash::hash(&self.adt_def, state)
}
}Hash, #[doc(hidden)]
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications,
clippy :: absolute_paths,)]
const _: () =
{
#[allow(unused_extern_crates, clippy :: useless_attribute)]
extern crate serde as _serde;
;
#[automatically_derived]
impl _serde::Serialize for VariantDef {
fn serialize<__S>(&self, __serializer: __S)
-> _serde::__private228::Result<__S::Ok, __S::Error> where
__S: _serde::Serializer {
let mut __serde_state =
_serde::Serializer::serialize_struct(__serializer,
"VariantDef", false as usize + 1 + 1)?;
_serde::ser::SerializeStruct::serialize_field(&mut __serde_state,
"idx", &self.idx)?;
_serde::ser::SerializeStruct::serialize_field(&mut __serde_state,
"adt_def", &self.adt_def)?;
_serde::ser::SerializeStruct::end(__serde_state)
}
}
};Serialize)]
248pub struct VariantDef {
249 pub(crate) idx: VariantIdx,
251 pub(crate) adt_def: AdtDef,
255}
256
257impl VariantDef {
258 pub fn name(&self) -> Symbol {
262 with(|cx| cx.variant_name(*self))
263 }
264
265 pub fn fields(&self) -> Vec<FieldDef> {
269 with(|cx| cx.variant_fields(*self))
270 }
271
272 pub fn idx(&self) -> VariantIdx {
274 self.idx
275 }
276
277 pub fn adt_def(&self) -> AdtDef {
279 self.adt_def
280 }
281}
282
283impl TraitDef {
284 pub fn declaration(trait_def: &TraitDef) -> TraitDecl {
285 with(|cx| cx.trait_decl(trait_def))
286 }
287
288 pub fn associated_items(&self) -> AssocItems {
289 with(|cx| cx.associated_items(self.def_id()))
290 }
291}
292
293impl ImplDef {
294 pub fn trait_impl(&self) -> ImplTrait {
296 with(|cx| cx.trait_impl(self))
297 }
298
299 pub fn associated_items(&self) -> AssocItems {
300 with(|cx| cx.associated_items(self.def_id()))
301 }
302
303 pub fn generics_of(&self) -> Generics {
305 with(|cx| cx.generics_of(self.0))
306 }
307}
308
309#[derive(#[automatically_derived]
impl ::core::clone::Clone for GenericParamDef {
#[inline]
fn clone(&self) -> GenericParamDef {
GenericParamDef {
name: ::core::clone::Clone::clone(&self.name),
def_id: ::core::clone::Clone::clone(&self.def_id),
index: ::core::clone::Clone::clone(&self.index),
pure_wrt_drop: ::core::clone::Clone::clone(&self.pure_wrt_drop),
kind: ::core::clone::Clone::clone(&self.kind),
}
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for GenericParamDef {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field5_finish(f,
"GenericParamDef", "name", &self.name, "def_id", &self.def_id,
"index", &self.index, "pure_wrt_drop", &self.pure_wrt_drop,
"kind", &&self.kind)
}
}Debug, #[automatically_derived]
impl ::core::cmp::Eq for GenericParamDef {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<Symbol>;
let _: ::core::cmp::AssertParamIsEq<GenericDef>;
let _: ::core::cmp::AssertParamIsEq<u32>;
let _: ::core::cmp::AssertParamIsEq<bool>;
let _: ::core::cmp::AssertParamIsEq<GenericParamDefKind>;
}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialEq for GenericParamDef {
#[inline]
fn eq(&self, other: &GenericParamDef) -> bool {
self.index == other.index && self.pure_wrt_drop == other.pure_wrt_drop
&& self.name == other.name && self.def_id == other.def_id &&
self.kind == other.kind
}
}PartialEq, #[doc(hidden)]
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications,
clippy :: absolute_paths,)]
const _: () =
{
#[allow(unused_extern_crates, clippy :: useless_attribute)]
extern crate serde as _serde;
;
#[automatically_derived]
impl _serde::Serialize for GenericParamDef {
fn serialize<__S>(&self, __serializer: __S)
-> _serde::__private228::Result<__S::Ok, __S::Error> where
__S: _serde::Serializer {
let mut __serde_state =
_serde::Serializer::serialize_struct(__serializer,
"GenericParamDef", false as usize + 1 + 1 + 1 + 1 + 1)?;
_serde::ser::SerializeStruct::serialize_field(&mut __serde_state,
"name", &self.name)?;
_serde::ser::SerializeStruct::serialize_field(&mut __serde_state,
"def_id", &self.def_id)?;
_serde::ser::SerializeStruct::serialize_field(&mut __serde_state,
"index", &self.index)?;
_serde::ser::SerializeStruct::serialize_field(&mut __serde_state,
"pure_wrt_drop", &self.pure_wrt_drop)?;
_serde::ser::SerializeStruct::serialize_field(&mut __serde_state,
"kind", &self.kind)?;
_serde::ser::SerializeStruct::end(__serde_state)
}
}
};Serialize)]
310pub struct GenericParamDef {
311 pub name: Symbol,
312 pub def_id: GenericDef,
313 pub index: u32,
314 pub pure_wrt_drop: bool,
315 pub kind: GenericParamDefKind,
316}