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