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