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