1use rustc_middle::ty::Ty;
4use rustc_middle::{mir, ty};
5use rustc_public_bridge::Tables;
6use rustc_public_bridge::context::CompilerCtxt;
7use rustc_span::bug;
8
9use crate::alloc;
10use crate::compiler_interface::BridgeTys;
11use crate::ty::{
12 AdtKind, FloatTy, GenericArgs, GenericParamDef, IntTy, Region, RigidTy, TyKind, UintTy,
13};
14use crate::unstable::Stable;
15
16impl<'tcx> Stable<'tcx> for ty::AliasTyKind<'tcx> {
17 type T = crate::ty::AliasKind;
18 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
19 match self {
20 ty::Projection { .. } => crate::ty::AliasKind::Projection,
21 ty::Inherent { .. } => crate::ty::AliasKind::Inherent,
22 ty::Opaque { .. } => crate::ty::AliasKind::Opaque,
23 ty::Free { .. } => crate::ty::AliasKind::Free,
24 }
25 }
26}
27
28impl<'tcx> Stable<'tcx> for ty::AliasTy<'tcx> {
29 type T = crate::ty::AliasTy;
30 fn stable<'cx>(
31 &self,
32 tables: &mut Tables<'cx, BridgeTys>,
33 cx: &CompilerCtxt<'cx, BridgeTys>,
34 ) -> Self::T {
35 let ty::AliasTy { args, kind, .. } = self;
36 let def_id = match *kind {
38 ty::AliasTyKind::Projection { def_id }
39 | ty::AliasTyKind::Inherent { def_id }
40 | ty::AliasTyKind::Opaque { def_id }
41 | ty::AliasTyKind::Free { def_id } => def_id,
42 };
43 crate::ty::AliasTy { def_id: tables.alias_def(def_id), args: args.stable(tables, cx) }
44 }
45}
46
47impl<'tcx> Stable<'tcx> for ty::AliasTerm<'tcx> {
48 type T = crate::ty::AliasTerm;
49 fn stable<'cx>(
50 &self,
51 tables: &mut Tables<'cx, BridgeTys>,
52 cx: &CompilerCtxt<'cx, BridgeTys>,
53 ) -> Self::T {
54 let ty::AliasTerm { args, kind, .. } = self;
55 let def_id = match *kind {
57 ty::AliasTermKind::ProjectionTy { def_id }
58 | ty::AliasTermKind::InherentTy { def_id }
59 | ty::AliasTermKind::OpaqueTy { def_id }
60 | ty::AliasTermKind::FreeTy { def_id }
61 | ty::AliasTermKind::AnonConst { def_id }
62 | ty::AliasTermKind::ProjectionConst { def_id }
63 | ty::AliasTermKind::FreeConst { def_id }
64 | ty::AliasTermKind::InherentConstSelf { def_id }
65 | ty::AliasTermKind::InherentConstImpl { def_id } => def_id,
66 };
67 crate::ty::AliasTerm { def_id: tables.alias_def(def_id), args: args.stable(tables, cx) }
68 }
69}
70
71impl<'tcx> Stable<'tcx> for ty::ExistentialPredicate<'tcx> {
72 type T = crate::ty::ExistentialPredicate;
73
74 fn stable<'cx>(
75 &self,
76 tables: &mut Tables<'cx, BridgeTys>,
77 cx: &CompilerCtxt<'cx, BridgeTys>,
78 ) -> Self::T {
79 use crate::ty::ExistentialPredicate::*;
80 match self {
81 ty::ExistentialPredicate::Trait(existential_trait_ref) => {
82 Trait(existential_trait_ref.stable(tables, cx))
83 }
84 ty::ExistentialPredicate::Projection(existential_projection) => {
85 Projection(existential_projection.stable(tables, cx))
86 }
87 ty::ExistentialPredicate::AutoTrait(def_id) => AutoTrait(tables.trait_def(*def_id)),
88 }
89 }
90}
91
92impl<'tcx> Stable<'tcx> for ty::ExistentialTraitRef<'tcx> {
93 type T = crate::ty::ExistentialTraitRef;
94
95 fn stable<'cx>(
96 &self,
97 tables: &mut Tables<'cx, BridgeTys>,
98 cx: &CompilerCtxt<'cx, BridgeTys>,
99 ) -> Self::T {
100 let ty::ExistentialTraitRef { def_id, args, .. } = self;
101 crate::ty::ExistentialTraitRef {
102 def_id: tables.trait_def(*def_id),
103 generic_args: args.stable(tables, cx),
104 }
105 }
106}
107
108impl<'tcx> Stable<'tcx> for ty::TermKind<'tcx> {
109 type T = crate::ty::TermKind;
110
111 fn stable<'cx>(
112 &self,
113 tables: &mut Tables<'cx, BridgeTys>,
114 cx: &CompilerCtxt<'cx, BridgeTys>,
115 ) -> Self::T {
116 use crate::ty::TermKind;
117 match self {
118 ty::TermKind::Ty(ty) => TermKind::Type(ty.stable(tables, cx)),
119 ty::TermKind::Const(cnst) => {
120 let cnst = cnst.stable(tables, cx);
121 TermKind::Const(cnst)
122 }
123 }
124 }
125}
126
127impl<'tcx> Stable<'tcx> for ty::ExistentialProjection<'tcx> {
128 type T = crate::ty::ExistentialProjection;
129
130 fn stable<'cx>(
131 &self,
132 tables: &mut Tables<'cx, BridgeTys>,
133 cx: &CompilerCtxt<'cx, BridgeTys>,
134 ) -> Self::T {
135 let ty::ExistentialProjection { def_id, args, term, .. } = self;
136 crate::ty::ExistentialProjection {
137 def_id: tables.trait_def(*def_id),
138 generic_args: args.stable(tables, cx),
139 term: term.kind().stable(tables, cx),
140 }
141 }
142}
143
144impl<'tcx> Stable<'tcx> for ty::adjustment::PointerCoercion {
145 type T = crate::mir::PointerCoercion;
146 fn stable<'cx>(
147 &self,
148 tables: &mut Tables<'cx, BridgeTys>,
149 cx: &CompilerCtxt<'cx, BridgeTys>,
150 ) -> Self::T {
151 use rustc_middle::ty::adjustment::PointerCoercion;
152 match self {
153 PointerCoercion::ReifyFnPointer(safety) => {
154 crate::mir::PointerCoercion::ReifyFnPointer(safety.stable(tables, cx))
155 }
156 PointerCoercion::UnsafeFnPointer => crate::mir::PointerCoercion::UnsafeFnPointer,
157 PointerCoercion::ClosureFnPointer(safety) => {
158 crate::mir::PointerCoercion::ClosureFnPointer(safety.stable(tables, cx))
159 }
160 PointerCoercion::MutToConstPointer => crate::mir::PointerCoercion::MutToConstPointer,
161 PointerCoercion::ArrayToPointer => crate::mir::PointerCoercion::ArrayToPointer,
162 PointerCoercion::Unsize => crate::mir::PointerCoercion::Unsize,
163 }
164 }
165}
166
167impl<'tcx> Stable<'tcx> for ty::UserTypeAnnotationIndex {
168 type T = usize;
169 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
170 self.as_usize()
171 }
172}
173
174impl<'tcx> Stable<'tcx> for ty::AdtKind {
175 type T = AdtKind;
176
177 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
178 match self {
179 ty::AdtKind::Struct => AdtKind::Struct,
180 ty::AdtKind::Union => AdtKind::Union,
181 ty::AdtKind::Enum => AdtKind::Enum,
182 }
183 }
184}
185
186impl<'tcx> Stable<'tcx> for ty::FieldDef {
187 type T = crate::ty::FieldDef;
188
189 fn stable<'cx>(
190 &self,
191 tables: &mut Tables<'cx, BridgeTys>,
192 cx: &CompilerCtxt<'cx, BridgeTys>,
193 ) -> Self::T {
194 crate::ty::FieldDef {
195 def: tables.create_def_id(self.did),
196 name: self.name.stable(tables, cx),
197 }
198 }
199}
200
201impl<'tcx> Stable<'tcx> for ty::GenericArgs<'tcx> {
202 type T = crate::ty::GenericArgs;
203 fn stable<'cx>(
204 &self,
205 tables: &mut Tables<'cx, BridgeTys>,
206 cx: &CompilerCtxt<'cx, BridgeTys>,
207 ) -> Self::T {
208 GenericArgs(self.iter().map(|arg| arg.kind().stable(tables, cx)).collect())
209 }
210}
211
212impl<'tcx> Stable<'tcx> for ty::GenericArgKind<'tcx> {
213 type T = crate::ty::GenericArgKind;
214
215 fn stable<'cx>(
216 &self,
217 tables: &mut Tables<'cx, BridgeTys>,
218 cx: &CompilerCtxt<'cx, BridgeTys>,
219 ) -> Self::T {
220 use crate::ty::GenericArgKind;
221 match self {
222 ty::GenericArgKind::Lifetime(region) => {
223 GenericArgKind::Lifetime(region.stable(tables, cx))
224 }
225 ty::GenericArgKind::Type(ty) => GenericArgKind::Type(ty.stable(tables, cx)),
226 ty::GenericArgKind::Const(cnst) => GenericArgKind::Const(cnst.stable(tables, cx)),
227 }
228 }
229}
230
231impl<'tcx, S, V> Stable<'tcx> for ty::Binder<'tcx, S>
232where
233 S: Stable<'tcx, T = V>,
234{
235 type T = crate::ty::Binder<V>;
236
237 fn stable<'cx>(
238 &self,
239 tables: &mut Tables<'cx, BridgeTys>,
240 cx: &CompilerCtxt<'cx, BridgeTys>,
241 ) -> Self::T {
242 use crate::ty::Binder;
243
244 Binder {
245 value: self.as_ref().skip_binder().stable(tables, cx),
246 bound_vars: self
247 .bound_vars()
248 .iter()
249 .map(|bound_var| bound_var.stable(tables, cx))
250 .collect(),
251 }
252 }
253}
254
255impl<'tcx, S, V> Stable<'tcx> for ty::EarlyBinder<'tcx, S>
256where
257 S: Stable<'tcx, T = V>,
258{
259 type T = crate::ty::EarlyBinder<V>;
260
261 fn stable<'cx>(
262 &self,
263 tables: &mut Tables<'cx, BridgeTys>,
264 cx: &CompilerCtxt<'cx, BridgeTys>,
265 ) -> Self::T {
266 use crate::ty::EarlyBinder;
267
268 EarlyBinder { value: self.as_ref().skip_binder().stable(tables, cx) }
269 }
270}
271
272impl<'tcx> Stable<'tcx> for ty::FnSigKind<'tcx> {
275 type T = (bool , crate::mir::Safety, crate::ty::Abi);
276 fn stable<'cx>(
277 &self,
278 tables: &mut Tables<'cx, BridgeTys>,
279 cx: &CompilerCtxt<'cx, BridgeTys>,
280 ) -> Self::T {
281 (
282 self.c_variadic(),
283 if self.is_safe() { crate::mir::Safety::Safe } else { crate::mir::Safety::Unsafe },
284 self.abi().stable(tables, cx),
285 )
286 }
287}
288
289impl<'tcx> Stable<'tcx> for ty::FnSig<'tcx> {
290 type T = crate::ty::FnSig;
291 fn stable<'cx>(
292 &self,
293 tables: &mut Tables<'cx, BridgeTys>,
294 cx: &CompilerCtxt<'cx, BridgeTys>,
295 ) -> Self::T {
296 use crate::ty::FnSig;
297 let (c_variadic, safety, abi) = self.fn_sig_kind.stable(tables, cx);
298
299 FnSig {
300 inputs_and_output: self
301 .inputs_and_output
302 .iter()
303 .map(|ty| ty.stable(tables, cx))
304 .collect(),
305 c_variadic,
306 safety,
307 abi,
308 }
309 }
310}
311
312impl<'tcx> Stable<'tcx> for ty::BoundTyKind<'tcx> {
313 type T = crate::ty::BoundTyKind;
314
315 fn stable<'cx>(
316 &self,
317 tables: &mut Tables<'cx, BridgeTys>,
318 cx: &CompilerCtxt<'cx, BridgeTys>,
319 ) -> Self::T {
320 use crate::ty::BoundTyKind;
321
322 match self {
323 ty::BoundTyKind::Anon => BoundTyKind::Anon,
324 ty::BoundTyKind::Param(def_id) => {
325 BoundTyKind::Param(tables.param_def(*def_id), cx.tcx.item_name(*def_id).to_string())
326 }
327 }
328 }
329}
330
331impl<'tcx> Stable<'tcx> for ty::BoundRegionKind<'tcx> {
332 type T = crate::ty::BoundRegionKind;
333
334 fn stable<'cx>(
335 &self,
336 tables: &mut Tables<'cx, BridgeTys>,
337 cx: &CompilerCtxt<'cx, BridgeTys>,
338 ) -> Self::T {
339 use crate::ty::BoundRegionKind;
340
341 match self {
342 ty::BoundRegionKind::Anon => BoundRegionKind::BrAnon,
343 ty::BoundRegionKind::Named(def_id) => BoundRegionKind::BrNamed(
344 tables.br_named_def(*def_id),
345 cx.tcx.item_name(*def_id).to_string(),
346 ),
347 ty::BoundRegionKind::ClosureEnv => BoundRegionKind::BrEnv,
348 ty::BoundRegionKind::NamedForPrinting(_) => ::rustc_span::macros::bug_impl(None,
format_args!("only used for pretty printing"), Location::caller())bug!("only used for pretty printing"),
349 }
350 }
351}
352
353impl<'tcx> Stable<'tcx> for ty::BoundVariableKind<'tcx> {
354 type T = crate::ty::BoundVariableKind;
355
356 fn stable<'cx>(
357 &self,
358 tables: &mut Tables<'cx, BridgeTys>,
359 cx: &CompilerCtxt<'cx, BridgeTys>,
360 ) -> Self::T {
361 use crate::ty::BoundVariableKind;
362
363 match self {
364 ty::BoundVariableKind::Ty(bound_ty_kind) => {
365 BoundVariableKind::Ty(bound_ty_kind.stable(tables, cx))
366 }
367 ty::BoundVariableKind::Region(bound_region_kind) => {
368 BoundVariableKind::Region(bound_region_kind.stable(tables, cx))
369 }
370 ty::BoundVariableKind::Const => BoundVariableKind::Const,
371 }
372 }
373}
374
375impl<'tcx> Stable<'tcx> for ty::IntTy {
376 type T = IntTy;
377
378 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
379 match self {
380 ty::IntTy::Isize => IntTy::Isize,
381 ty::IntTy::I8 => IntTy::I8,
382 ty::IntTy::I16 => IntTy::I16,
383 ty::IntTy::I32 => IntTy::I32,
384 ty::IntTy::I64 => IntTy::I64,
385 ty::IntTy::I128 => IntTy::I128,
386 }
387 }
388}
389
390impl<'tcx> Stable<'tcx> for ty::UintTy {
391 type T = UintTy;
392
393 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
394 match self {
395 ty::UintTy::Usize => UintTy::Usize,
396 ty::UintTy::U8 => UintTy::U8,
397 ty::UintTy::U16 => UintTy::U16,
398 ty::UintTy::U32 => UintTy::U32,
399 ty::UintTy::U64 => UintTy::U64,
400 ty::UintTy::U128 => UintTy::U128,
401 }
402 }
403}
404
405impl<'tcx> Stable<'tcx> for ty::FloatTy {
406 type T = FloatTy;
407
408 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
409 match self {
410 ty::FloatTy::F16 => FloatTy::F16,
411 ty::FloatTy::F32 => FloatTy::F32,
412 ty::FloatTy::F64 => FloatTy::F64,
413 ty::FloatTy::F128 => FloatTy::F128,
414 }
415 }
416}
417
418impl<'tcx> Stable<'tcx> for Ty<'tcx> {
419 type T = crate::ty::Ty;
420 fn stable<'cx>(
421 &self,
422 tables: &mut Tables<'cx, BridgeTys>,
423 cx: &CompilerCtxt<'cx, BridgeTys>,
424 ) -> Self::T {
425 tables.intern_ty(cx.lift(*self))
426 }
427}
428
429impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> {
430 type T = crate::ty::TyKind;
431 fn stable<'cx>(
432 &self,
433 tables: &mut Tables<'cx, BridgeTys>,
434 cx: &CompilerCtxt<'cx, BridgeTys>,
435 ) -> Self::T {
436 match self {
437 ty::Bool => TyKind::RigidTy(RigidTy::Bool),
438 ty::Char => TyKind::RigidTy(RigidTy::Char),
439 ty::Int(int_ty) => TyKind::RigidTy(RigidTy::Int(int_ty.stable(tables, cx))),
440 ty::Uint(uint_ty) => TyKind::RigidTy(RigidTy::Uint(uint_ty.stable(tables, cx))),
441 ty::Float(float_ty) => TyKind::RigidTy(RigidTy::Float(float_ty.stable(tables, cx))),
442 ty::Adt(adt_def, generic_args) => TyKind::RigidTy(RigidTy::Adt(
443 tables.adt_def(adt_def.did()),
444 generic_args.stable(tables, cx),
445 )),
446 ty::Foreign(def_id) => TyKind::RigidTy(RigidTy::Foreign(tables.foreign_def(*def_id))),
447 ty::Str => TyKind::RigidTy(RigidTy::Str),
448 ty::Array(ty, constant) => {
449 TyKind::RigidTy(RigidTy::Array(ty.stable(tables, cx), constant.stable(tables, cx)))
450 }
451 ty::Pat(ty, pat) => {
452 TyKind::RigidTy(RigidTy::Pat(ty.stable(tables, cx), pat.stable(tables, cx)))
453 }
454 ty::Slice(ty) => TyKind::RigidTy(RigidTy::Slice(ty.stable(tables, cx))),
455 ty::RawPtr(ty, mutbl) => {
456 TyKind::RigidTy(RigidTy::RawPtr(ty.stable(tables, cx), mutbl.stable(tables, cx)))
457 }
458 ty::Ref(region, ty, mutbl) => TyKind::RigidTy(RigidTy::Ref(
459 region.stable(tables, cx),
460 ty.stable(tables, cx),
461 mutbl.stable(tables, cx),
462 )),
463 ty::FnDef(def_id, generic_args) => TyKind::RigidTy(RigidTy::FnDef(
464 tables.fn_def(*def_id),
465 generic_args.no_bound_vars().unwrap().stable(tables, cx),
466 )),
467 ty::FnPtr(sig_tys, hdr) => {
468 TyKind::RigidTy(RigidTy::FnPtr(sig_tys.with(*hdr).stable(tables, cx)))
469 }
470 ty::UnsafeBinder(_) => ::core::panicking::panic("not implemented")unimplemented!(),
472 ty::Dynamic(existential_predicates, region) => TyKind::RigidTy(RigidTy::Dynamic(
473 existential_predicates
474 .iter()
475 .map(|existential_predicate| existential_predicate.stable(tables, cx))
476 .collect(),
477 region.stable(tables, cx),
478 )),
479 ty::Closure(def_id, generic_args) => TyKind::RigidTy(RigidTy::Closure(
480 tables.closure_def(*def_id),
481 generic_args.stable(tables, cx),
482 )),
483 ty::CoroutineClosure(..) => {
484 {
::core::panicking::panic_fmt(format_args!("not implemented: {0}",
format_args!("FIXME(async_closures): Lower these to SMIR")));
}unimplemented!("FIXME(async_closures): Lower these to SMIR")
485 }
486 ty::Coroutine(def_id, generic_args) => TyKind::RigidTy(RigidTy::Coroutine(
487 tables.coroutine_def(*def_id),
488 generic_args.stable(tables, cx),
489 )),
490 ty::Never => TyKind::RigidTy(RigidTy::Never),
491 ty::Tuple(fields) => TyKind::RigidTy(RigidTy::Tuple(
492 fields.iter().map(|ty| ty.stable(tables, cx)).collect(),
493 )),
494 ty::Alias(_, alias_ty) => {
495 TyKind::Alias(alias_ty.kind.stable(tables, cx), alias_ty.stable(tables, cx))
496 }
497 ty::Param(param_ty) => TyKind::Param(param_ty.stable(tables, cx)),
498 ty::Bound(ty::BoundVarIndexKind::Canonical, _) => {
499 ::core::panicking::panic("internal error: entered unreachable code")unreachable!()
500 }
501 ty::Bound(ty::BoundVarIndexKind::Bound(debruijn_idx), bound_ty) => {
502 TyKind::Bound(debruijn_idx.as_usize(), bound_ty.stable(tables, cx))
503 }
504 ty::CoroutineWitness(def_id, args) => TyKind::RigidTy(RigidTy::CoroutineWitness(
505 tables.coroutine_witness_def(*def_id),
506 args.stable(tables, cx),
507 )),
508 ty::Placeholder(..) | ty::Infer(_) | ty::Error(_) => {
509 ::core::panicking::panic("internal error: entered unreachable code");unreachable!();
510 }
511 }
512 }
513}
514
515impl<'tcx> Stable<'tcx> for ty::Pattern<'tcx> {
516 type T = crate::ty::Pattern;
517
518 fn stable<'cx>(
519 &self,
520 tables: &mut Tables<'cx, BridgeTys>,
521 cx: &CompilerCtxt<'cx, BridgeTys>,
522 ) -> Self::T {
523 match **self {
524 ty::PatternKind::Range { start, end } => crate::ty::Pattern::Range {
525 start: start.stable(tables, cx),
526 end: end.stable(tables, cx),
527 include_end: true,
528 },
529 ty::PatternKind::NotNull => crate::ty::Pattern::NotNull,
530 ty::PatternKind::Or(pats) => {
531 crate::ty::Pattern::Or(pats.iter().map(|pat| pat.stable(tables, cx)).collect())
532 }
533 }
534 }
535}
536
537impl<'tcx> Stable<'tcx> for ty::Const<'tcx> {
538 type T = crate::ty::TyConst;
539
540 fn stable<'cx>(
541 &self,
542 tables: &mut Tables<'cx, BridgeTys>,
543 cx: &CompilerCtxt<'cx, BridgeTys>,
544 ) -> Self::T {
545 let ct = cx.lift(*self);
546 let kind = match ct.kind() {
547 ty::ConstKind::Value(cv) => {
548 let const_val = cx.valtree_to_const_val(cv);
549 if #[allow(non_exhaustive_omitted_patterns)] match const_val {
mir::ConstValue::ZeroSized => true,
_ => false,
}matches!(const_val, mir::ConstValue::ZeroSized) {
550 crate::ty::TyConstKind::ZSTValue(cv.ty.stable(tables, cx))
551 } else {
552 crate::ty::TyConstKind::Value(
553 cv.ty.stable(tables, cx),
554 alloc::new_allocation(cv.ty, const_val, tables, cx),
555 )
556 }
557 }
558 ty::ConstKind::Param(param) => crate::ty::TyConstKind::Param(param.stable(tables, cx)),
559 ty::ConstKind::Alias(_, alias_const) => {
560 let def_id = match alias_const.kind {
562 ty::AliasConstKind::Projection { def_id }
563 | ty::AliasConstKind::InherentSelf { def_id }
564 | ty::AliasConstKind::InherentImpl { def_id }
565 | ty::AliasConstKind::Free { def_id }
566 | ty::AliasConstKind::Anon { def_id } => def_id,
567 };
568 crate::ty::TyConstKind::Unevaluated(
569 tables.const_def(def_id),
570 alias_const.args.stable(tables, cx),
571 )
572 }
573 ty::ConstKind::Error(_) => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
574 ty::ConstKind::Infer(_) => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
575 ty::ConstKind::Bound(_, _) => ::core::panicking::panic("not implemented")unimplemented!(),
576 ty::ConstKind::Placeholder(_) => ::core::panicking::panic("not implemented")unimplemented!(),
577 ty::ConstKind::Expr(_) => ::core::panicking::panic("not implemented")unimplemented!(),
578 };
579 let id = tables.intern_ty_const(ct);
580 crate::ty::TyConst::new(kind, id)
581 }
582}
583
584impl<'tcx> Stable<'tcx> for ty::ParamConst {
585 type T = crate::ty::ParamConst;
586 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
587 use crate::ty::ParamConst;
588 ParamConst { index: self.index, name: self.name.to_string() }
589 }
590}
591
592impl<'tcx> Stable<'tcx> for ty::ParamTy {
593 type T = crate::ty::ParamTy;
594 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
595 use crate::ty::ParamTy;
596 ParamTy { index: self.index, name: self.name.to_string() }
597 }
598}
599
600impl<'tcx> Stable<'tcx> for ty::BoundTy<'tcx> {
601 type T = crate::ty::BoundTy;
602 fn stable<'cx>(
603 &self,
604 tables: &mut Tables<'cx, BridgeTys>,
605 cx: &CompilerCtxt<'cx, BridgeTys>,
606 ) -> Self::T {
607 use crate::ty::BoundTy;
608 BoundTy { var: self.var.as_usize(), kind: self.kind.stable(tables, cx) }
609 }
610}
611
612impl<'tcx> Stable<'tcx> for ty::trait_def::TraitSpecializationKind {
613 type T = crate::ty::TraitSpecializationKind;
614 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
615 use crate::ty::TraitSpecializationKind;
616
617 match self {
618 ty::trait_def::TraitSpecializationKind::None => TraitSpecializationKind::None,
619 ty::trait_def::TraitSpecializationKind::Marker => TraitSpecializationKind::Marker,
620 ty::trait_def::TraitSpecializationKind::AlwaysApplicable => {
621 TraitSpecializationKind::AlwaysApplicable
622 }
623 }
624 }
625}
626
627impl<'tcx> Stable<'tcx> for ty::TraitDef {
628 type T = crate::ty::TraitDecl;
629 fn stable<'cx>(
630 &self,
631 tables: &mut Tables<'cx, BridgeTys>,
632 cx: &CompilerCtxt<'cx, BridgeTys>,
633 ) -> Self::T {
634 use crate::opaque;
635 use crate::ty::TraitDecl;
636
637 TraitDecl {
638 def_id: tables.trait_def(self.def_id),
639 safety: self.safety.stable(tables, cx),
640 paren_sugar: self.paren_sugar,
641 has_auto_impl: self.has_auto_impl,
642 is_marker: self.is_marker,
643 is_coinductive: self.is_coinductive,
644 skip_array_during_method_dispatch: self.skip_array_during_method_dispatch,
645 skip_boxed_slice_during_method_dispatch: self.skip_boxed_slice_during_method_dispatch,
646 specialization_kind: self.specialization_kind.stable(tables, cx),
647 must_implement_one_of: self
648 .must_implement_one_of
649 .as_ref()
650 .map(|idents| idents.iter().map(|ident| opaque(ident)).collect()),
651 force_dyn_incompatible: self.force_dyn_incompatible.stable(tables, cx),
652 deny_explicit_impl: self.deny_explicit_impl,
653 }
654 }
655}
656
657impl<'tcx> Stable<'tcx> for ty::TraitRef<'tcx> {
658 type T = crate::ty::TraitRef;
659 fn stable<'cx>(
660 &self,
661 tables: &mut Tables<'cx, BridgeTys>,
662 cx: &CompilerCtxt<'cx, BridgeTys>,
663 ) -> Self::T {
664 use crate::ty::TraitRef;
665
666 TraitRef::try_new(tables.trait_def(self.def_id), self.args.stable(tables, cx)).unwrap()
667 }
668}
669
670impl<'tcx> Stable<'tcx> for ty::Generics {
671 type T = crate::ty::Generics;
672
673 fn stable<'cx>(
674 &self,
675 tables: &mut Tables<'cx, BridgeTys>,
676 cx: &CompilerCtxt<'cx, BridgeTys>,
677 ) -> Self::T {
678 use crate::ty::Generics;
679
680 let params: Vec<_> = self.own_params.iter().map(|param| param.stable(tables, cx)).collect();
681 let param_def_id_to_index =
682 params.iter().map(|param| (param.def_id, param.index)).collect();
683
684 Generics {
685 parent: self.parent.map(|did| tables.generic_def(did)),
686 parent_count: self.parent_count,
687 params,
688 param_def_id_to_index,
689 has_self: self.has_self,
690 has_late_bound_regions: self
691 .has_late_bound_regions
692 .as_ref()
693 .map(|late_bound_regions| late_bound_regions.stable(tables, cx)),
694 }
695 }
696}
697
698impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDefKind {
699 type T = crate::ty::GenericParamDefKind;
700
701 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
702 use crate::ty::GenericParamDefKind;
703 match *self {
704 ty::GenericParamDefKind::Lifetime => GenericParamDefKind::Lifetime,
705 ty::GenericParamDefKind::Type { has_default, synthetic } => {
706 GenericParamDefKind::Type { has_default, synthetic }
707 }
708 ty::GenericParamDefKind::Const { has_default } => {
709 GenericParamDefKind::Const { has_default }
710 }
711 }
712 }
713}
714
715impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDef {
716 type T = crate::ty::GenericParamDef;
717
718 fn stable<'cx>(
719 &self,
720 tables: &mut Tables<'cx, BridgeTys>,
721 cx: &CompilerCtxt<'cx, BridgeTys>,
722 ) -> Self::T {
723 GenericParamDef {
724 name: self.name.to_string(),
725 def_id: tables.generic_def(self.def_id),
726 index: self.index,
727 pure_wrt_drop: self.pure_wrt_drop,
728 kind: self.kind.stable(tables, cx),
729 }
730 }
731}
732
733impl<'tcx> Stable<'tcx> for ty::PredicateKind<'tcx> {
734 type T = crate::ty::PredicateKind;
735
736 fn stable<'cx>(
737 &self,
738 tables: &mut Tables<'cx, BridgeTys>,
739 cx: &CompilerCtxt<'cx, BridgeTys>,
740 ) -> Self::T {
741 use rustc_middle::ty::PredicateKind;
742 match self {
743 PredicateKind::Clause(clause_kind) => {
744 crate::ty::PredicateKind::Clause(clause_kind.stable(tables, cx))
745 }
746 PredicateKind::DynCompatible(did) => {
747 crate::ty::PredicateKind::DynCompatible(tables.trait_def(*did))
748 }
749 PredicateKind::Subtype(subtype_predicate) => {
750 crate::ty::PredicateKind::SubType(subtype_predicate.stable(tables, cx))
751 }
752 PredicateKind::Coerce(coerce_predicate) => {
753 crate::ty::PredicateKind::Coerce(coerce_predicate.stable(tables, cx))
754 }
755 PredicateKind::ConstEquate(a, b) => {
756 crate::ty::PredicateKind::ConstEquate(a.stable(tables, cx), b.stable(tables, cx))
757 }
758 PredicateKind::Ambiguous => crate::ty::PredicateKind::Ambiguous,
759 PredicateKind::NormalizesTo(_pred) => ::core::panicking::panic("not implemented")unimplemented!(),
760 }
761 }
762}
763
764impl<'tcx> Stable<'tcx> for ty::ClauseKind<'tcx> {
765 type T = crate::ty::ClauseKind;
766
767 fn stable<'cx>(
768 &self,
769 tables: &mut Tables<'cx, BridgeTys>,
770 cx: &CompilerCtxt<'cx, BridgeTys>,
771 ) -> Self::T {
772 use rustc_middle::ty::ClauseKind;
773 match *self {
774 ClauseKind::Trait(trait_object) => {
775 crate::ty::ClauseKind::Trait(trait_object.stable(tables, cx))
776 }
777 ClauseKind::RegionOutlives(region_outlives) => {
778 crate::ty::ClauseKind::RegionOutlives(region_outlives.stable(tables, cx))
779 }
780 ClauseKind::TypeOutlives(type_outlives) => {
781 let ty::OutlivesClause::<_, _>(a, b) = type_outlives;
782 crate::ty::ClauseKind::TypeOutlives(crate::ty::OutlivesClause(
783 a.stable(tables, cx),
784 b.stable(tables, cx),
785 ))
786 }
787 ClauseKind::Projection(projection_predicate) => {
788 crate::ty::ClauseKind::Projection(projection_predicate.stable(tables, cx))
789 }
790 ClauseKind::ConstArgHasType(const_, ty) => crate::ty::ClauseKind::ConstArgHasType(
791 const_.stable(tables, cx),
792 ty.stable(tables, cx),
793 ),
794 ClauseKind::WellFormed(term) => {
795 crate::ty::ClauseKind::WellFormed(term.kind().stable(tables, cx))
796 }
797 ClauseKind::ConstEvaluatable(const_) => {
798 crate::ty::ClauseKind::ConstEvaluatable(const_.stable(tables, cx))
799 }
800 ClauseKind::HostEffect(..) => {
801 ::core::panicking::panic("not implemented")unimplemented!()
802 }
803 ClauseKind::UnstableFeature(_) => {
804 ::core::panicking::panic("not implemented")unimplemented!()
805 }
806 }
807 }
808}
809
810impl<'tcx> Stable<'tcx> for ty::ClosureKind {
811 type T = crate::ty::ClosureKind;
812
813 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
814 use rustc_middle::ty::ClosureKind::*;
815 match self {
816 Fn => crate::ty::ClosureKind::Fn,
817 FnMut => crate::ty::ClosureKind::FnMut,
818 FnOnce => crate::ty::ClosureKind::FnOnce,
819 }
820 }
821}
822
823impl<'tcx> Stable<'tcx> for ty::SubtypePredicate<'tcx> {
824 type T = crate::ty::SubtypePredicate;
825
826 fn stable<'cx>(
827 &self,
828 tables: &mut Tables<'cx, BridgeTys>,
829 cx: &CompilerCtxt<'cx, BridgeTys>,
830 ) -> Self::T {
831 let ty::SubtypePredicate { a, b, a_is_expected: _ } = self;
832 crate::ty::SubtypePredicate { a: a.stable(tables, cx), b: b.stable(tables, cx) }
833 }
834}
835
836impl<'tcx> Stable<'tcx> for ty::CoercePredicate<'tcx> {
837 type T = crate::ty::CoercePredicate;
838
839 fn stable<'cx>(
840 &self,
841 tables: &mut Tables<'cx, BridgeTys>,
842 cx: &CompilerCtxt<'cx, BridgeTys>,
843 ) -> Self::T {
844 let ty::CoercePredicate { a, b } = self;
845 crate::ty::CoercePredicate { a: a.stable(tables, cx), b: b.stable(tables, cx) }
846 }
847}
848
849impl<'tcx> Stable<'tcx> for ty::TraitClause<'tcx> {
850 type T = crate::ty::TraitClause;
851
852 fn stable<'cx>(
853 &self,
854 tables: &mut Tables<'cx, BridgeTys>,
855 cx: &CompilerCtxt<'cx, BridgeTys>,
856 ) -> Self::T {
857 let ty::TraitClause { trait_ref, polarity } = self;
858 crate::ty::TraitClause {
859 trait_ref: trait_ref.stable(tables, cx),
860 polarity: polarity.stable(tables, cx),
861 }
862 }
863}
864
865impl<'tcx, T> Stable<'tcx> for ty::OutlivesClause<'tcx, T>
866where
867 T: Stable<'tcx>,
868{
869 type T = crate::ty::OutlivesClause<T::T, Region>;
870
871 fn stable<'cx>(
872 &self,
873 tables: &mut Tables<'cx, BridgeTys>,
874 cx: &CompilerCtxt<'cx, BridgeTys>,
875 ) -> Self::T {
876 let ty::OutlivesClause(a, b) = self;
877 crate::ty::OutlivesClause(a.stable(tables, cx), b.stable(tables, cx))
878 }
879}
880
881impl<'tcx> Stable<'tcx> for ty::ProjectionClause<'tcx> {
882 type T = crate::ty::ProjectionClause;
883
884 fn stable<'cx>(
885 &self,
886 tables: &mut Tables<'cx, BridgeTys>,
887 cx: &CompilerCtxt<'cx, BridgeTys>,
888 ) -> Self::T {
889 let ty::ProjectionClause { projection_term, term } = self;
890 crate::ty::ProjectionClause {
891 projection_term: projection_term.stable(tables, cx),
892 term: term.kind().stable(tables, cx),
893 }
894 }
895}
896
897impl<'tcx> Stable<'tcx> for ty::ImplPolarity {
898 type T = crate::ty::ImplPolarity;
899
900 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
901 use rustc_middle::ty::ImplPolarity::*;
902 match self {
903 Positive => crate::ty::ImplPolarity::Positive,
904 Negative => crate::ty::ImplPolarity::Negative,
905 }
906 }
907}
908
909impl<'tcx> Stable<'tcx> for ty::ClausePolarity {
910 type T = crate::ty::ClausePolarity;
911
912 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
913 use rustc_middle::ty::ClausePolarity::*;
914 match self {
915 Positive => crate::ty::ClausePolarity::Positive,
916 Negative => crate::ty::ClausePolarity::Negative,
917 }
918 }
919}
920
921impl<'tcx> Stable<'tcx> for ty::Region<'tcx> {
922 type T = crate::ty::Region;
923
924 fn stable<'cx>(
925 &self,
926 tables: &mut Tables<'cx, BridgeTys>,
927 cx: &CompilerCtxt<'cx, BridgeTys>,
928 ) -> Self::T {
929 Region { kind: self.kind().stable(tables, cx) }
930 }
931}
932
933impl<'tcx> Stable<'tcx> for ty::RegionKind<'tcx> {
934 type T = crate::ty::RegionKind;
935
936 fn stable<'cx>(
937 &self,
938 tables: &mut Tables<'cx, BridgeTys>,
939 cx: &CompilerCtxt<'cx, BridgeTys>,
940 ) -> Self::T {
941 use crate::ty::{BoundRegion, EarlyParamRegion, RegionKind};
942 match self {
943 ty::ReEarlyParam(early_reg) => RegionKind::ReEarlyParam(EarlyParamRegion {
944 index: early_reg.index,
945 name: early_reg.name.to_string(),
946 }),
947 ty::ReBound(ty::BoundVarIndexKind::Bound(db_index), bound_reg) => RegionKind::ReBound(
948 db_index.as_u32(),
949 BoundRegion {
950 var: bound_reg.var.as_u32(),
951 kind: bound_reg.kind.stable(tables, cx),
952 },
953 ),
954 ty::ReStatic => RegionKind::ReStatic,
955 ty::RePlaceholder(place_holder) => RegionKind::RePlaceholder(crate::ty::Placeholder {
956 universe: place_holder.universe.as_u32(),
957 bound: BoundRegion {
958 var: place_holder.bound.var.as_u32(),
959 kind: place_holder.bound.kind.stable(tables, cx),
960 },
961 }),
962 ty::ReErased => RegionKind::ReErased,
963 _ => {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("{0:?}", self)));
}unreachable!("{self:?}"),
964 }
965 }
966}
967
968impl<'tcx> Stable<'tcx> for ty::Instance<'tcx> {
969 type T = crate::mir::mono::Instance;
970
971 fn stable<'cx>(
972 &self,
973 tables: &mut Tables<'cx, BridgeTys>,
974 cx: &CompilerCtxt<'cx, BridgeTys>,
975 ) -> Self::T {
976 let def = tables.instance_def(cx.lift(*self));
977 let kind = match self.def {
978 ty::InstanceKind::Item(..) => crate::mir::mono::InstanceKind::Item,
979 ty::InstanceKind::Intrinsic(..) => crate::mir::mono::InstanceKind::Intrinsic,
980 ty::InstanceKind::LlvmIntrinsic(..) => crate::mir::mono::InstanceKind::LlvmIntrinsic,
981 ty::InstanceKind::Virtual(_def_id, idx) => {
982 crate::mir::mono::InstanceKind::Virtual { idx }
983 }
984 ty::InstanceKind::Shim(..) => crate::mir::mono::InstanceKind::Shim,
985 };
986 crate::mir::mono::Instance { def, kind }
987 }
988}
989
990impl<'tcx> Stable<'tcx> for ty::Variance {
991 type T = crate::mir::Variance;
992 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
993 match self {
994 ty::Bivariant => crate::mir::Variance::Bivariant,
995 ty::Contravariant => crate::mir::Variance::Contravariant,
996 ty::Covariant => crate::mir::Variance::Covariant,
997 ty::Invariant => crate::mir::Variance::Invariant,
998 }
999 }
1000}
1001
1002impl<'tcx> Stable<'tcx> for ty::Movability {
1003 type T = crate::ty::Movability;
1004
1005 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
1006 match self {
1007 ty::Movability::Static => crate::ty::Movability::Static,
1008 ty::Movability::Movable => crate::ty::Movability::Movable,
1009 }
1010 }
1011}
1012
1013impl<'tcx> Stable<'tcx> for rustc_abi::ExternAbi {
1014 type T = crate::ty::Abi;
1015
1016 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
1017 use rustc_abi::ExternAbi;
1018
1019 use crate::ty::Abi;
1020 match *self {
1021 ExternAbi::Rust => Abi::Rust,
1022 ExternAbi::C { unwind } => Abi::C { unwind },
1023 ExternAbi::Cdecl { unwind } => Abi::Cdecl { unwind },
1024 ExternAbi::Stdcall { unwind } => Abi::Stdcall { unwind },
1025 ExternAbi::Fastcall { unwind } => Abi::Fastcall { unwind },
1026 ExternAbi::Vectorcall { unwind } => Abi::Vectorcall { unwind },
1027 ExternAbi::Thiscall { unwind } => Abi::Thiscall { unwind },
1028 ExternAbi::Aapcs { unwind } => Abi::Aapcs { unwind },
1029 ExternAbi::Win64 { unwind } => Abi::Win64 { unwind },
1030 ExternAbi::SysV64 { unwind } => Abi::SysV64 { unwind },
1031 ExternAbi::PtxKernel => Abi::PtxKernel,
1032 ExternAbi::GpuKernel => Abi::GpuKernel,
1033 ExternAbi::Msp430Interrupt => Abi::Msp430Interrupt,
1034 ExternAbi::X86Interrupt => Abi::X86Interrupt,
1035 ExternAbi::EfiApi => Abi::EfiApi,
1036 ExternAbi::AvrInterrupt => Abi::AvrInterrupt,
1037 ExternAbi::AvrNonBlockingInterrupt => Abi::AvrNonBlockingInterrupt,
1038 ExternAbi::CmseNonSecureCall => Abi::CCmseNonSecureCall,
1039 ExternAbi::CmseNonSecureEntry => Abi::CCmseNonSecureEntry,
1040 ExternAbi::System { unwind } => Abi::System { unwind },
1041 ExternAbi::RustCall => Abi::RustCall,
1042 ExternAbi::LlvmIntrinsic => Abi::LlvmIntrinsic,
1043 ExternAbi::RustCold => Abi::RustCold,
1044 ExternAbi::RustPreserveNone => Abi::RustPreserveNone,
1045 ExternAbi::RustTail => Abi::RustTail,
1046 ExternAbi::RustInvalid => Abi::RustInvalid,
1047 ExternAbi::RiscvInterruptM => Abi::RiscvInterruptM,
1048 ExternAbi::RiscvInterruptS => Abi::RiscvInterruptS,
1049 ExternAbi::Custom => Abi::Custom,
1050 ExternAbi::Swift => Abi::Swift,
1051 }
1052 }
1053}
1054
1055impl<'tcx> Stable<'tcx> for rustc_crate_store::ForeignModule {
1056 type T = crate::ty::ForeignModule;
1057
1058 fn stable<'cx>(
1059 &self,
1060 tables: &mut Tables<'cx, BridgeTys>,
1061 cx: &CompilerCtxt<'cx, BridgeTys>,
1062 ) -> Self::T {
1063 crate::ty::ForeignModule {
1064 def_id: tables.foreign_module_def(self.def_id),
1065 abi: self.abi.stable(tables, cx),
1066 }
1067 }
1068}
1069
1070impl<'tcx> Stable<'tcx> for ty::AssocKind {
1071 type T = crate::ty::AssocKind;
1072
1073 fn stable<'cx>(
1074 &self,
1075 tables: &mut Tables<'cx, BridgeTys>,
1076 cx: &CompilerCtxt<'cx, BridgeTys>,
1077 ) -> Self::T {
1078 use crate::ty::{AssocKind, AssocTypeData};
1079 match *self {
1080 ty::AssocKind::Const { name, .. } => AssocKind::Const { name: name.to_string() },
1081 ty::AssocKind::Fn { name, has_self } => {
1082 AssocKind::Fn { name: name.to_string(), has_self }
1083 }
1084 ty::AssocKind::Type { data } => AssocKind::Type {
1085 data: match data {
1086 ty::AssocTypeData::Normal(name) => AssocTypeData::Normal(name.to_string()),
1087 ty::AssocTypeData::Rpitit(rpitit) => {
1088 AssocTypeData::Rpitit(rpitit.stable(tables, cx))
1089 }
1090 },
1091 },
1092 }
1093 }
1094}
1095
1096impl<'tcx> Stable<'tcx> for ty::AssocContainer {
1097 type T = crate::ty::AssocContainer;
1098
1099 fn stable(
1100 &self,
1101 tables: &mut Tables<'_, BridgeTys>,
1102 _: &CompilerCtxt<'_, BridgeTys>,
1103 ) -> Self::T {
1104 use crate::ty::AssocContainer;
1105 match self {
1106 ty::AssocContainer::Trait => AssocContainer::Trait,
1107 ty::AssocContainer::InherentImpl => AssocContainer::InherentImpl,
1108 ty::AssocContainer::TraitImpl(trait_item_id) => {
1109 AssocContainer::TraitImpl(tables.assoc_def(trait_item_id.unwrap()))
1110 }
1111 }
1112 }
1113}
1114
1115impl<'tcx> Stable<'tcx> for ty::AssocItem {
1116 type T = crate::ty::AssocItem;
1117
1118 fn stable<'cx>(
1119 &self,
1120 tables: &mut Tables<'cx, BridgeTys>,
1121 cx: &CompilerCtxt<'cx, BridgeTys>,
1122 ) -> Self::T {
1123 crate::ty::AssocItem {
1124 def_id: tables.assoc_def(self.def_id),
1125 kind: self.kind.stable(tables, cx),
1126 container: self.container.stable(tables, cx),
1127 }
1128 }
1129}
1130
1131impl<'tcx> Stable<'tcx> for ty::ImplTraitInTraitData {
1132 type T = crate::ty::ImplTraitInTraitData;
1133
1134 fn stable<'cx>(
1135 &self,
1136 tables: &mut Tables<'cx, BridgeTys>,
1137 _: &CompilerCtxt<'cx, BridgeTys>,
1138 ) -> Self::T {
1139 use crate::ty::ImplTraitInTraitData;
1140 match self {
1141 ty::ImplTraitInTraitData::Trait { fn_def_id, opaque_def_id } => {
1142 ImplTraitInTraitData::Trait {
1143 fn_def_id: tables.fn_def(*fn_def_id),
1144 opaque_def_id: tables.opaque_def(*opaque_def_id),
1145 }
1146 }
1147 ty::ImplTraitInTraitData::Impl { fn_def_id } => {
1148 ImplTraitInTraitData::Impl { fn_def_id: tables.fn_def(*fn_def_id) }
1149 }
1150 }
1151 }
1152}
1153
1154impl<'tcx> Stable<'tcx> for rustc_middle::ty::util::Discr<'tcx> {
1155 type T = crate::ty::Discr;
1156
1157 fn stable<'cx>(
1158 &self,
1159 tables: &mut Tables<'cx, BridgeTys>,
1160 cx: &CompilerCtxt<'cx, BridgeTys>,
1161 ) -> Self::T {
1162 crate::ty::Discr { val: self.val, ty: self.ty.stable(tables, cx) }
1163 }
1164}
1165
1166impl<'tcx> Stable<'tcx> for rustc_middle::ty::VtblEntry<'tcx> {
1167 type T = crate::ty::VtblEntry;
1168
1169 fn stable<'cx>(
1170 &self,
1171 tables: &mut Tables<'cx, BridgeTys>,
1172 cx: &CompilerCtxt<'cx, BridgeTys>,
1173 ) -> Self::T {
1174 use crate::ty::VtblEntry;
1175 match self {
1176 ty::VtblEntry::MetadataDropInPlace => VtblEntry::MetadataDropInPlace,
1177 ty::VtblEntry::MetadataSize => VtblEntry::MetadataSize,
1178 ty::VtblEntry::MetadataAlign => VtblEntry::MetadataAlign,
1179 ty::VtblEntry::Vacant => VtblEntry::Vacant,
1180 ty::VtblEntry::Method(instance) => VtblEntry::Method(instance.stable(tables, cx)),
1181 ty::VtblEntry::TraitVPtr(trait_ref) => {
1182 VtblEntry::TraitVPtr(trait_ref.stable(tables, cx))
1183 }
1184 }
1185 }
1186}