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::unimplemented_default_msg()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::unreachable_default_msg()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::unreachable_default_msg();unreachable!();
510 }
511
512 ty::View(..) => ::core::panicking::unimplemented_default_msg()unimplemented!(),
514 }
515 }
516}
517
518impl<'tcx> Stable<'tcx> for ty::Pattern<'tcx> {
519 type T = crate::ty::Pattern;
520
521 fn stable<'cx>(
522 &self,
523 tables: &mut Tables<'cx, BridgeTys>,
524 cx: &CompilerCtxt<'cx, BridgeTys>,
525 ) -> Self::T {
526 match **self {
527 ty::PatternKind::Range { start, end } => crate::ty::Pattern::Range {
528 start: start.stable(tables, cx),
529 end: end.stable(tables, cx),
530 include_end: true,
531 },
532 ty::PatternKind::NotNull => crate::ty::Pattern::NotNull,
533 ty::PatternKind::Or(pats) => {
534 crate::ty::Pattern::Or(pats.iter().map(|pat| pat.stable(tables, cx)).collect())
535 }
536 }
537 }
538}
539
540impl<'tcx> Stable<'tcx> for ty::Const<'tcx> {
541 type T = crate::ty::TyConst;
542
543 fn stable<'cx>(
544 &self,
545 tables: &mut Tables<'cx, BridgeTys>,
546 cx: &CompilerCtxt<'cx, BridgeTys>,
547 ) -> Self::T {
548 let ct = cx.lift(*self);
549 let kind = match ct.kind() {
550 ty::ConstKind::Value(cv) => {
551 let const_val = cx.valtree_to_const_val(cv);
552 if #[allow(non_exhaustive_omitted_patterns)] match const_val {
mir::ConstValue::ZeroSized => true,
_ => false,
}matches!(const_val, mir::ConstValue::ZeroSized) {
553 crate::ty::TyConstKind::ZSTValue(cv.ty.stable(tables, cx))
554 } else {
555 crate::ty::TyConstKind::Value(
556 cv.ty.stable(tables, cx),
557 alloc::new_allocation(cv.ty, const_val, tables, cx),
558 )
559 }
560 }
561 ty::ConstKind::Param(param) => crate::ty::TyConstKind::Param(param.stable(tables, cx)),
562 ty::ConstKind::Alias(_, alias_const) => {
563 let def_id = match alias_const.kind {
565 ty::AliasConstKind::Projection { def_id }
566 | ty::AliasConstKind::InherentSelf { def_id }
567 | ty::AliasConstKind::InherentImpl { def_id }
568 | ty::AliasConstKind::Free { def_id }
569 | ty::AliasConstKind::Anon { def_id } => def_id,
570 };
571 crate::ty::TyConstKind::Unevaluated(
572 tables.const_def(def_id),
573 alias_const.args.stable(tables, cx),
574 )
575 }
576 ty::ConstKind::Error(_) => ::core::panicking::unreachable_default_msg()unreachable!(),
577 ty::ConstKind::Infer(_) => ::core::panicking::unreachable_default_msg()unreachable!(),
578 ty::ConstKind::Bound(_, _) => ::core::panicking::unimplemented_default_msg()unimplemented!(),
579 ty::ConstKind::Placeholder(_) => ::core::panicking::unimplemented_default_msg()unimplemented!(),
580 ty::ConstKind::Expr(_) => ::core::panicking::unimplemented_default_msg()unimplemented!(),
581 };
582 let id = tables.intern_ty_const(ct);
583 crate::ty::TyConst::new(kind, id)
584 }
585}
586
587impl<'tcx> Stable<'tcx> for ty::ParamConst {
588 type T = crate::ty::ParamConst;
589 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
590 use crate::ty::ParamConst;
591 ParamConst { index: self.index, name: self.name.to_string() }
592 }
593}
594
595impl<'tcx> Stable<'tcx> for ty::ParamTy {
596 type T = crate::ty::ParamTy;
597 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
598 use crate::ty::ParamTy;
599 ParamTy { index: self.index, name: self.name.to_string() }
600 }
601}
602
603impl<'tcx> Stable<'tcx> for ty::BoundTy<'tcx> {
604 type T = crate::ty::BoundTy;
605 fn stable<'cx>(
606 &self,
607 tables: &mut Tables<'cx, BridgeTys>,
608 cx: &CompilerCtxt<'cx, BridgeTys>,
609 ) -> Self::T {
610 use crate::ty::BoundTy;
611 BoundTy { var: self.var.as_usize(), kind: self.kind.stable(tables, cx) }
612 }
613}
614
615impl<'tcx> Stable<'tcx> for ty::trait_def::TraitSpecializationKind {
616 type T = crate::ty::TraitSpecializationKind;
617 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
618 use crate::ty::TraitSpecializationKind;
619
620 match self {
621 ty::trait_def::TraitSpecializationKind::None => TraitSpecializationKind::None,
622 ty::trait_def::TraitSpecializationKind::Marker => TraitSpecializationKind::Marker,
623 ty::trait_def::TraitSpecializationKind::AlwaysApplicable => {
624 TraitSpecializationKind::AlwaysApplicable
625 }
626 }
627 }
628}
629
630impl<'tcx> Stable<'tcx> for ty::TraitDef {
631 type T = crate::ty::TraitDecl;
632 fn stable<'cx>(
633 &self,
634 tables: &mut Tables<'cx, BridgeTys>,
635 cx: &CompilerCtxt<'cx, BridgeTys>,
636 ) -> Self::T {
637 use crate::opaque;
638 use crate::ty::TraitDecl;
639
640 TraitDecl {
641 def_id: tables.trait_def(self.def_id),
642 safety: self.safety.stable(tables, cx),
643 paren_sugar: self.paren_sugar,
644 has_auto_impl: self.has_auto_impl,
645 is_marker: self.is_marker,
646 is_coinductive: self.is_coinductive,
647 skip_array_during_method_dispatch: self.skip_array_during_method_dispatch,
648 skip_boxed_slice_during_method_dispatch: self.skip_boxed_slice_during_method_dispatch,
649 specialization_kind: self.specialization_kind.stable(tables, cx),
650 must_implement_one_of: self
651 .must_implement_one_of
652 .as_ref()
653 .map(|idents| idents.iter().map(|ident| opaque(ident)).collect()),
654 force_dyn_incompatible: self.force_dyn_incompatible.stable(tables, cx),
655 deny_explicit_impl: self.deny_explicit_impl,
656 }
657 }
658}
659
660impl<'tcx> Stable<'tcx> for ty::TraitRef<'tcx> {
661 type T = crate::ty::TraitRef;
662 fn stable<'cx>(
663 &self,
664 tables: &mut Tables<'cx, BridgeTys>,
665 cx: &CompilerCtxt<'cx, BridgeTys>,
666 ) -> Self::T {
667 use crate::ty::TraitRef;
668
669 TraitRef::try_new(tables.trait_def(self.def_id), self.args.stable(tables, cx)).unwrap()
670 }
671}
672
673impl<'tcx> Stable<'tcx> for ty::Generics {
674 type T = crate::ty::Generics;
675
676 fn stable<'cx>(
677 &self,
678 tables: &mut Tables<'cx, BridgeTys>,
679 cx: &CompilerCtxt<'cx, BridgeTys>,
680 ) -> Self::T {
681 use crate::ty::Generics;
682
683 let params: Vec<_> = self.own_params.iter().map(|param| param.stable(tables, cx)).collect();
684 let param_def_id_to_index =
685 params.iter().map(|param| (param.def_id, param.index)).collect();
686
687 Generics {
688 parent: self.parent.map(|did| tables.generic_def(did)),
689 parent_count: self.parent_count,
690 params,
691 param_def_id_to_index,
692 has_self: self.has_self,
693 has_late_bound_regions: self
694 .has_late_bound_regions
695 .as_ref()
696 .map(|late_bound_regions| late_bound_regions.stable(tables, cx)),
697 }
698 }
699}
700
701impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDefKind {
702 type T = crate::ty::GenericParamDefKind;
703
704 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
705 use crate::ty::GenericParamDefKind;
706 match *self {
707 ty::GenericParamDefKind::Lifetime => GenericParamDefKind::Lifetime,
708 ty::GenericParamDefKind::Type { has_default, synthetic } => {
709 GenericParamDefKind::Type { has_default, synthetic }
710 }
711 ty::GenericParamDefKind::Const { has_default, arg_pos: _ } => {
712 GenericParamDefKind::Const { has_default }
713 }
714 }
715 }
716}
717
718impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDef {
719 type T = crate::ty::GenericParamDef;
720
721 fn stable<'cx>(
722 &self,
723 tables: &mut Tables<'cx, BridgeTys>,
724 cx: &CompilerCtxt<'cx, BridgeTys>,
725 ) -> Self::T {
726 GenericParamDef {
727 name: self.name.to_string(),
728 def_id: tables.generic_def(self.def_id),
729 index: self.index,
730 pure_wrt_drop: self.pure_wrt_drop,
731 kind: self.kind.stable(tables, cx),
732 }
733 }
734}
735
736impl<'tcx> Stable<'tcx> for ty::PredicateKind<'tcx> {
737 type T = crate::ty::PredicateKind;
738
739 fn stable<'cx>(
740 &self,
741 tables: &mut Tables<'cx, BridgeTys>,
742 cx: &CompilerCtxt<'cx, BridgeTys>,
743 ) -> Self::T {
744 use rustc_middle::ty::PredicateKind;
745 match self {
746 PredicateKind::Clause(clause_kind) => {
747 crate::ty::PredicateKind::Clause(clause_kind.stable(tables, cx))
748 }
749 PredicateKind::DynCompatible(did) => {
750 crate::ty::PredicateKind::DynCompatible(tables.trait_def(*did))
751 }
752 PredicateKind::Subtype(subtype_predicate) => {
753 crate::ty::PredicateKind::SubType(subtype_predicate.stable(tables, cx))
754 }
755 PredicateKind::Coerce(coerce_predicate) => {
756 crate::ty::PredicateKind::Coerce(coerce_predicate.stable(tables, cx))
757 }
758 PredicateKind::ConstEquate(a, b) => {
759 crate::ty::PredicateKind::ConstEquate(a.stable(tables, cx), b.stable(tables, cx))
760 }
761 PredicateKind::Ambiguous => crate::ty::PredicateKind::Ambiguous,
762 PredicateKind::NormalizesTo(_pred) => ::core::panicking::unimplemented_default_msg()unimplemented!(),
763 }
764 }
765}
766
767impl<'tcx> Stable<'tcx> for ty::ClauseKind<'tcx> {
768 type T = crate::ty::ClauseKind;
769
770 fn stable<'cx>(
771 &self,
772 tables: &mut Tables<'cx, BridgeTys>,
773 cx: &CompilerCtxt<'cx, BridgeTys>,
774 ) -> Self::T {
775 use rustc_middle::ty::ClauseKind;
776 match *self {
777 ClauseKind::Trait(trait_object) => {
778 crate::ty::ClauseKind::Trait(trait_object.stable(tables, cx))
779 }
780 ClauseKind::RegionOutlives(region_outlives) => {
781 crate::ty::ClauseKind::RegionOutlives(region_outlives.stable(tables, cx))
782 }
783 ClauseKind::TypeOutlives(type_outlives) => {
784 let ty::OutlivesClause::<_, _>(a, b) = type_outlives;
785 crate::ty::ClauseKind::TypeOutlives(crate::ty::OutlivesClause(
786 a.stable(tables, cx),
787 b.stable(tables, cx),
788 ))
789 }
790 ClauseKind::Projection(projection_predicate) => {
791 crate::ty::ClauseKind::Projection(projection_predicate.stable(tables, cx))
792 }
793 ClauseKind::ConstArgHasType(const_, ty) => crate::ty::ClauseKind::ConstArgHasType(
794 const_.stable(tables, cx),
795 ty.stable(tables, cx),
796 ),
797 ClauseKind::WellFormed(term) => {
798 crate::ty::ClauseKind::WellFormed(term.kind().stable(tables, cx))
799 }
800 ClauseKind::ConstEvaluatable(const_) => {
801 crate::ty::ClauseKind::ConstEvaluatable(const_.stable(tables, cx))
802 }
803 ClauseKind::CompressedTrait(_) => {
804 ::core::panicking::unreachable_default_msg()unreachable!()
805 }
806 ClauseKind::HostEffect(..) => {
807 ::core::panicking::unimplemented_default_msg()unimplemented!()
808 }
809 ClauseKind::UnstableFeature(_) => {
810 ::core::panicking::unimplemented_default_msg()unimplemented!()
811 }
812 }
813 }
814}
815
816impl<'tcx> Stable<'tcx> for ty::ClosureKind {
817 type T = crate::ty::ClosureKind;
818
819 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
820 use rustc_middle::ty::ClosureKind::*;
821 match self {
822 Fn => crate::ty::ClosureKind::Fn,
823 FnMut => crate::ty::ClosureKind::FnMut,
824 FnOnce => crate::ty::ClosureKind::FnOnce,
825 }
826 }
827}
828
829impl<'tcx> Stable<'tcx> for ty::SubtypePredicate<'tcx> {
830 type T = crate::ty::SubtypePredicate;
831
832 fn stable<'cx>(
833 &self,
834 tables: &mut Tables<'cx, BridgeTys>,
835 cx: &CompilerCtxt<'cx, BridgeTys>,
836 ) -> Self::T {
837 let ty::SubtypePredicate { a, b, a_is_expected: _ } = self;
838 crate::ty::SubtypePredicate { a: a.stable(tables, cx), b: b.stable(tables, cx) }
839 }
840}
841
842impl<'tcx> Stable<'tcx> for ty::CoercePredicate<'tcx> {
843 type T = crate::ty::CoercePredicate;
844
845 fn stable<'cx>(
846 &self,
847 tables: &mut Tables<'cx, BridgeTys>,
848 cx: &CompilerCtxt<'cx, BridgeTys>,
849 ) -> Self::T {
850 let ty::CoercePredicate { a, b } = self;
851 crate::ty::CoercePredicate { a: a.stable(tables, cx), b: b.stable(tables, cx) }
852 }
853}
854
855impl<'tcx> Stable<'tcx> for ty::TraitClause<'tcx> {
856 type T = crate::ty::TraitClause;
857
858 fn stable<'cx>(
859 &self,
860 tables: &mut Tables<'cx, BridgeTys>,
861 cx: &CompilerCtxt<'cx, BridgeTys>,
862 ) -> Self::T {
863 let ty::TraitClause { trait_ref, polarity } = self;
864 crate::ty::TraitClause {
865 trait_ref: trait_ref.stable(tables, cx),
866 polarity: polarity.stable(tables, cx),
867 }
868 }
869}
870
871impl<'tcx, T> Stable<'tcx> for ty::OutlivesClause<'tcx, T>
872where
873 T: Stable<'tcx>,
874{
875 type T = crate::ty::OutlivesClause<T::T, Region>;
876
877 fn stable<'cx>(
878 &self,
879 tables: &mut Tables<'cx, BridgeTys>,
880 cx: &CompilerCtxt<'cx, BridgeTys>,
881 ) -> Self::T {
882 let ty::OutlivesClause(a, b) = self;
883 crate::ty::OutlivesClause(a.stable(tables, cx), b.stable(tables, cx))
884 }
885}
886
887impl<'tcx> Stable<'tcx> for ty::ProjectionClause<'tcx> {
888 type T = crate::ty::ProjectionClause;
889
890 fn stable<'cx>(
891 &self,
892 tables: &mut Tables<'cx, BridgeTys>,
893 cx: &CompilerCtxt<'cx, BridgeTys>,
894 ) -> Self::T {
895 let ty::ProjectionClause { projection_term, term } = self;
896 crate::ty::ProjectionClause {
897 projection_term: projection_term.stable(tables, cx),
898 term: term.kind().stable(tables, cx),
899 }
900 }
901}
902
903impl<'tcx> Stable<'tcx> for ty::ImplPolarity {
904 type T = crate::ty::ImplPolarity;
905
906 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
907 use rustc_middle::ty::ImplPolarity::*;
908 match self {
909 Positive => crate::ty::ImplPolarity::Positive,
910 Negative => crate::ty::ImplPolarity::Negative,
911 }
912 }
913}
914
915impl<'tcx> Stable<'tcx> for ty::ClausePolarity {
916 type T = crate::ty::ClausePolarity;
917
918 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
919 use rustc_middle::ty::ClausePolarity::*;
920 match self {
921 Positive => crate::ty::ClausePolarity::Positive,
922 Negative => crate::ty::ClausePolarity::Negative,
923 }
924 }
925}
926
927impl<'tcx> Stable<'tcx> for ty::Region<'tcx> {
928 type T = crate::ty::Region;
929
930 fn stable<'cx>(
931 &self,
932 tables: &mut Tables<'cx, BridgeTys>,
933 cx: &CompilerCtxt<'cx, BridgeTys>,
934 ) -> Self::T {
935 Region { kind: self.kind().stable(tables, cx) }
936 }
937}
938
939impl<'tcx> Stable<'tcx> for ty::RegionKind<'tcx> {
940 type T = crate::ty::RegionKind;
941
942 fn stable<'cx>(
943 &self,
944 tables: &mut Tables<'cx, BridgeTys>,
945 cx: &CompilerCtxt<'cx, BridgeTys>,
946 ) -> Self::T {
947 use crate::ty::{BoundRegion, EarlyParamRegion, RegionKind};
948 match self {
949 ty::ReEarlyParam(early_reg) => RegionKind::ReEarlyParam(EarlyParamRegion {
950 index: early_reg.index,
951 name: early_reg.name.to_string(),
952 }),
953 ty::ReBound(ty::BoundVarIndexKind::Bound(db_index), bound_reg) => RegionKind::ReBound(
954 db_index.as_u32(),
955 BoundRegion {
956 var: bound_reg.var.as_u32(),
957 kind: bound_reg.kind.stable(tables, cx),
958 },
959 ),
960 ty::ReStatic => RegionKind::ReStatic,
961 ty::RePlaceholder(place_holder) => RegionKind::RePlaceholder(crate::ty::Placeholder {
962 universe: place_holder.universe.as_u32(),
963 bound: BoundRegion {
964 var: place_holder.bound.var.as_u32(),
965 kind: place_holder.bound.kind.stable(tables, cx),
966 },
967 }),
968 ty::ReErased => RegionKind::ReErased,
969 _ => {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("{0:?}", self)));
}unreachable!("{self:?}"),
970 }
971 }
972}
973
974impl<'tcx> Stable<'tcx> for ty::Instance<'tcx> {
975 type T = crate::mir::mono::Instance;
976
977 fn stable<'cx>(
978 &self,
979 tables: &mut Tables<'cx, BridgeTys>,
980 cx: &CompilerCtxt<'cx, BridgeTys>,
981 ) -> Self::T {
982 let def = tables.instance_def(cx.lift(*self));
983 let kind = match self.def {
984 ty::InstanceKind::Item(..) => crate::mir::mono::InstanceKind::Item,
985 ty::InstanceKind::Intrinsic(..) => crate::mir::mono::InstanceKind::Intrinsic,
986 ty::InstanceKind::LlvmIntrinsic(..) => crate::mir::mono::InstanceKind::LlvmIntrinsic,
987 ty::InstanceKind::Virtual(_def_id, idx) => {
988 crate::mir::mono::InstanceKind::Virtual { idx }
989 }
990 ty::InstanceKind::Shim(..) => crate::mir::mono::InstanceKind::Shim,
991 };
992 crate::mir::mono::Instance { def, kind }
993 }
994}
995
996impl<'tcx> Stable<'tcx> for ty::Variance {
997 type T = crate::mir::Variance;
998 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
999 match self {
1000 ty::Bivariant => crate::mir::Variance::Bivariant,
1001 ty::Contravariant => crate::mir::Variance::Contravariant,
1002 ty::Covariant => crate::mir::Variance::Covariant,
1003 ty::Invariant => crate::mir::Variance::Invariant,
1004 }
1005 }
1006}
1007
1008impl<'tcx> Stable<'tcx> for ty::Movability {
1009 type T = crate::ty::Movability;
1010
1011 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
1012 match self {
1013 ty::Movability::Static => crate::ty::Movability::Static,
1014 ty::Movability::Movable => crate::ty::Movability::Movable,
1015 }
1016 }
1017}
1018
1019impl<'tcx> Stable<'tcx> for rustc_abi::ExternAbi {
1020 type T = crate::ty::Abi;
1021
1022 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
1023 use rustc_abi::ExternAbi;
1024
1025 use crate::ty::Abi;
1026 match *self {
1027 ExternAbi::Rust => Abi::Rust,
1028 ExternAbi::C { unwind } => Abi::C { unwind },
1029 ExternAbi::Cdecl { unwind } => Abi::Cdecl { unwind },
1030 ExternAbi::Stdcall { unwind } => Abi::Stdcall { unwind },
1031 ExternAbi::Fastcall { unwind } => Abi::Fastcall { unwind },
1032 ExternAbi::Vectorcall { unwind } => Abi::Vectorcall { unwind },
1033 ExternAbi::Thiscall { unwind } => Abi::Thiscall { unwind },
1034 ExternAbi::Aapcs { unwind } => Abi::Aapcs { unwind },
1035 ExternAbi::Win64 { unwind } => Abi::Win64 { unwind },
1036 ExternAbi::SysV64 { unwind } => Abi::SysV64 { unwind },
1037 ExternAbi::PtxKernel => Abi::PtxKernel,
1038 ExternAbi::GpuKernel => Abi::GpuKernel,
1039 ExternAbi::Msp430Interrupt => Abi::Msp430Interrupt,
1040 ExternAbi::X86Interrupt => Abi::X86Interrupt,
1041 ExternAbi::EfiApi => Abi::EfiApi,
1042 ExternAbi::AvrInterrupt => Abi::AvrInterrupt,
1043 ExternAbi::AvrNonBlockingInterrupt => Abi::AvrNonBlockingInterrupt,
1044 ExternAbi::CmseNonSecureCall => Abi::CCmseNonSecureCall,
1045 ExternAbi::CmseNonSecureEntry => Abi::CCmseNonSecureEntry,
1046 ExternAbi::System { unwind } => Abi::System { unwind },
1047 ExternAbi::RustCall => Abi::RustCall,
1048 ExternAbi::LlvmIntrinsic => Abi::LlvmIntrinsic,
1049 ExternAbi::RustCold => Abi::RustCold,
1050 ExternAbi::RustPreserveNone => Abi::RustPreserveNone,
1051 ExternAbi::RustTail => Abi::RustTail,
1052 ExternAbi::RustInvalid => Abi::RustInvalid,
1053 ExternAbi::RiscvInterruptM => Abi::RiscvInterruptM,
1054 ExternAbi::RiscvInterruptS => Abi::RiscvInterruptS,
1055 ExternAbi::Custom => Abi::Custom,
1056 ExternAbi::Swift => Abi::Swift,
1057 }
1058 }
1059}
1060
1061impl<'tcx> Stable<'tcx> for rustc_crate_store::ForeignModule {
1062 type T = crate::ty::ForeignModule;
1063
1064 fn stable<'cx>(
1065 &self,
1066 tables: &mut Tables<'cx, BridgeTys>,
1067 cx: &CompilerCtxt<'cx, BridgeTys>,
1068 ) -> Self::T {
1069 crate::ty::ForeignModule {
1070 def_id: tables.foreign_module_def(self.def_id),
1071 abi: self.abi.stable(tables, cx),
1072 }
1073 }
1074}
1075
1076impl<'tcx> Stable<'tcx> for ty::AssocKind {
1077 type T = crate::ty::AssocKind;
1078
1079 fn stable<'cx>(
1080 &self,
1081 tables: &mut Tables<'cx, BridgeTys>,
1082 cx: &CompilerCtxt<'cx, BridgeTys>,
1083 ) -> Self::T {
1084 use crate::ty::{AssocConstData, AssocKind, AssocTypeData};
1085 match *self {
1086 ty::AssocKind::Const { data, .. } => AssocKind::Const {
1087 data: match data {
1088 ty::AssocConstData::Named(name) => AssocConstData::Named(name.to_string()),
1089 ty::AssocConstData::Anonymous => AssocConstData::Anonymous,
1090 },
1091 },
1092 ty::AssocKind::Fn { name, has_self } => {
1093 AssocKind::Fn { name: name.to_string(), has_self }
1094 }
1095 ty::AssocKind::Type { data } => AssocKind::Type {
1096 data: match data {
1097 ty::AssocTypeData::Normal(name) => AssocTypeData::Normal(name.to_string()),
1098 ty::AssocTypeData::Rpitit(rpitit) => {
1099 AssocTypeData::Rpitit(rpitit.stable(tables, cx))
1100 }
1101 },
1102 },
1103 }
1104 }
1105}
1106
1107impl<'tcx> Stable<'tcx> for ty::AssocContainer {
1108 type T = crate::ty::AssocContainer;
1109
1110 fn stable(
1111 &self,
1112 tables: &mut Tables<'_, BridgeTys>,
1113 _: &CompilerCtxt<'_, BridgeTys>,
1114 ) -> Self::T {
1115 use crate::ty::AssocContainer;
1116 match self {
1117 ty::AssocContainer::Trait => AssocContainer::Trait,
1118 ty::AssocContainer::InherentImpl => AssocContainer::InherentImpl,
1119 ty::AssocContainer::TraitImpl(trait_item_id) => {
1120 AssocContainer::TraitImpl(tables.assoc_def(trait_item_id.unwrap()))
1121 }
1122 }
1123 }
1124}
1125
1126impl<'tcx> Stable<'tcx> for ty::AssocItem {
1127 type T = crate::ty::AssocItem;
1128
1129 fn stable<'cx>(
1130 &self,
1131 tables: &mut Tables<'cx, BridgeTys>,
1132 cx: &CompilerCtxt<'cx, BridgeTys>,
1133 ) -> Self::T {
1134 crate::ty::AssocItem {
1135 def_id: tables.assoc_def(self.def_id),
1136 kind: self.kind.stable(tables, cx),
1137 container: self.container.stable(tables, cx),
1138 }
1139 }
1140}
1141
1142impl<'tcx> Stable<'tcx> for ty::ImplTraitInTraitData {
1143 type T = crate::ty::ImplTraitInTraitData;
1144
1145 fn stable<'cx>(
1146 &self,
1147 tables: &mut Tables<'cx, BridgeTys>,
1148 _: &CompilerCtxt<'cx, BridgeTys>,
1149 ) -> Self::T {
1150 use crate::ty::ImplTraitInTraitData;
1151 match self {
1152 ty::ImplTraitInTraitData::Trait { fn_def_id, opaque_def_id } => {
1153 ImplTraitInTraitData::Trait {
1154 fn_def_id: tables.fn_def(*fn_def_id),
1155 opaque_def_id: tables.opaque_def(*opaque_def_id),
1156 }
1157 }
1158 ty::ImplTraitInTraitData::Impl { fn_def_id } => {
1159 ImplTraitInTraitData::Impl { fn_def_id: tables.fn_def(*fn_def_id) }
1160 }
1161 }
1162 }
1163}
1164
1165impl<'tcx> Stable<'tcx> for rustc_middle::ty::util::Discr<'tcx> {
1166 type T = crate::ty::Discr;
1167
1168 fn stable<'cx>(
1169 &self,
1170 tables: &mut Tables<'cx, BridgeTys>,
1171 cx: &CompilerCtxt<'cx, BridgeTys>,
1172 ) -> Self::T {
1173 crate::ty::Discr { val: self.val, ty: self.ty.stable(tables, cx) }
1174 }
1175}
1176
1177impl<'tcx> Stable<'tcx> for rustc_middle::ty::VtblEntry<'tcx> {
1178 type T = crate::ty::VtblEntry;
1179
1180 fn stable<'cx>(
1181 &self,
1182 tables: &mut Tables<'cx, BridgeTys>,
1183 cx: &CompilerCtxt<'cx, BridgeTys>,
1184 ) -> Self::T {
1185 use crate::ty::VtblEntry;
1186 match self {
1187 ty::VtblEntry::MetadataDropInPlace => VtblEntry::MetadataDropInPlace,
1188 ty::VtblEntry::MetadataSize => VtblEntry::MetadataSize,
1189 ty::VtblEntry::MetadataAlign => VtblEntry::MetadataAlign,
1190 ty::VtblEntry::Vacant => VtblEntry::Vacant,
1191 ty::VtblEntry::Method(instance) => VtblEntry::Method(instance.stable(tables, cx)),
1192 ty::VtblEntry::TraitVPtr(trait_ref) => {
1193 VtblEntry::TraitVPtr(trait_ref.stable(tables, cx))
1194 }
1195 }
1196 }
1197}