Skip to main content

rustc_public/unstable/convert/stable/
ty.rs

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