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 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 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
270impl<'tcx> Stable<'tcx> for ty::FnSigKind<'tcx> {
273 type T = (bool , 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.no_bound_vars().unwrap().stable(tables, cx),
464 )),
465 ty::FnPtr(sig_tys, hdr) => {
466 TyKind::RigidTy(RigidTy::FnPtr(sig_tys.with(*hdr).stable(tables, cx)))
467 }
468 ty::UnsafeBinder(_) => ::core::panicking::panic("not implemented")unimplemented!(),
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(..) => {
482 {
::core::panicking::panic_fmt(format_args!("not implemented: {0}",
format_args!("FIXME(async_closures): Lower these to SMIR")));
}unimplemented!("FIXME(async_closures): Lower these to SMIR")
483 }
484 ty::Coroutine(def_id, generic_args) => TyKind::RigidTy(RigidTy::Coroutine(
485 tables.coroutine_def(*def_id),
486 generic_args.stable(tables, cx),
487 )),
488 ty::Never => TyKind::RigidTy(RigidTy::Never),
489 ty::Tuple(fields) => TyKind::RigidTy(RigidTy::Tuple(
490 fields.iter().map(|ty| ty.stable(tables, cx)).collect(),
491 )),
492 ty::Alias(_, alias_ty) => {
493 TyKind::Alias(alias_ty.kind.stable(tables, cx), alias_ty.stable(tables, cx))
494 }
495 ty::Param(param_ty) => TyKind::Param(param_ty.stable(tables, cx)),
496 ty::Bound(ty::BoundVarIndexKind::Canonical, _) => {
497 ::core::panicking::panic("internal error: entered unreachable code")unreachable!()
498 }
499 ty::Bound(ty::BoundVarIndexKind::Bound(debruijn_idx), bound_ty) => {
500 TyKind::Bound(debruijn_idx.as_usize(), bound_ty.stable(tables, cx))
501 }
502 ty::CoroutineWitness(def_id, args) => TyKind::RigidTy(RigidTy::CoroutineWitness(
503 tables.coroutine_witness_def(*def_id),
504 args.stable(tables, cx),
505 )),
506 ty::Placeholder(..) | ty::Infer(_) | ty::Error(_) => {
507 ::core::panicking::panic("internal error: entered unreachable code");unreachable!();
508 }
509 }
510 }
511}
512
513impl<'tcx> Stable<'tcx> for ty::Pattern<'tcx> {
514 type T = crate::ty::Pattern;
515
516 fn stable<'cx>(
517 &self,
518 tables: &mut Tables<'cx, BridgeTys>,
519 cx: &CompilerCtxt<'cx, BridgeTys>,
520 ) -> Self::T {
521 match **self {
522 ty::PatternKind::Range { start, end } => crate::ty::Pattern::Range {
523 start: start.stable(tables, cx),
524 end: end.stable(tables, cx),
525 include_end: true,
526 },
527 ty::PatternKind::NotNull => crate::ty::Pattern::NotNull,
528 ty::PatternKind::Or(pats) => {
529 crate::ty::Pattern::Or(pats.iter().map(|pat| pat.stable(tables, cx)).collect())
530 }
531 }
532 }
533}
534
535impl<'tcx> Stable<'tcx> for ty::Const<'tcx> {
536 type T = crate::ty::TyConst;
537
538 fn stable<'cx>(
539 &self,
540 tables: &mut Tables<'cx, BridgeTys>,
541 cx: &CompilerCtxt<'cx, BridgeTys>,
542 ) -> Self::T {
543 let ct = cx.lift(*self);
544 let kind = match ct.kind() {
545 ty::ConstKind::Value(cv) => {
546 let const_val = cx.valtree_to_const_val(cv);
547 if #[allow(non_exhaustive_omitted_patterns)] match const_val {
mir::ConstValue::ZeroSized => true,
_ => false,
}matches!(const_val, mir::ConstValue::ZeroSized) {
548 crate::ty::TyConstKind::ZSTValue(cv.ty.stable(tables, cx))
549 } else {
550 crate::ty::TyConstKind::Value(
551 cv.ty.stable(tables, cx),
552 alloc::new_allocation(cv.ty, const_val, tables, cx),
553 )
554 }
555 }
556 ty::ConstKind::Param(param) => crate::ty::TyConstKind::Param(param.stable(tables, cx)),
557 ty::ConstKind::Alias(_, alias_const) => {
558 let Some(def_id) = alias_const.kind.opt_def_id() else {
559 {
::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")
561 };
562 crate::ty::TyConstKind::Unevaluated(
563 tables.const_def(def_id),
564 alias_const.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 }
755 }
756}
757
758impl<'tcx> Stable<'tcx> for ty::ClauseKind<'tcx> {
759 type T = crate::ty::ClauseKind;
760
761 fn stable<'cx>(
762 &self,
763 tables: &mut Tables<'cx, BridgeTys>,
764 cx: &CompilerCtxt<'cx, BridgeTys>,
765 ) -> Self::T {
766 use rustc_middle::ty::ClauseKind;
767 match *self {
768 ClauseKind::Trait(trait_object) => {
769 crate::ty::ClauseKind::Trait(trait_object.stable(tables, cx))
770 }
771 ClauseKind::RegionOutlives(region_outlives) => {
772 crate::ty::ClauseKind::RegionOutlives(region_outlives.stable(tables, cx))
773 }
774 ClauseKind::TypeOutlives(type_outlives) => {
775 let ty::OutlivesPredicate::<_, _>(a, b) = type_outlives;
776 crate::ty::ClauseKind::TypeOutlives(crate::ty::OutlivesPredicate(
777 a.stable(tables, cx),
778 b.stable(tables, cx),
779 ))
780 }
781 ClauseKind::Projection(projection_predicate) => {
782 crate::ty::ClauseKind::Projection(projection_predicate.stable(tables, cx))
783 }
784 ClauseKind::ConstArgHasType(const_, ty) => crate::ty::ClauseKind::ConstArgHasType(
785 const_.stable(tables, cx),
786 ty.stable(tables, cx),
787 ),
788 ClauseKind::WellFormed(term) => {
789 crate::ty::ClauseKind::WellFormed(term.kind().stable(tables, cx))
790 }
791 ClauseKind::ConstEvaluatable(const_) => {
792 crate::ty::ClauseKind::ConstEvaluatable(const_.stable(tables, cx))
793 }
794 ClauseKind::HostEffect(..) => {
795 ::core::panicking::panic("not implemented")unimplemented!()
796 }
797 ClauseKind::UnstableFeature(_) => {
798 ::core::panicking::panic("not implemented")unimplemented!()
799 }
800 }
801 }
802}
803
804impl<'tcx> Stable<'tcx> for ty::ClosureKind {
805 type T = crate::ty::ClosureKind;
806
807 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
808 use rustc_middle::ty::ClosureKind::*;
809 match self {
810 Fn => crate::ty::ClosureKind::Fn,
811 FnMut => crate::ty::ClosureKind::FnMut,
812 FnOnce => crate::ty::ClosureKind::FnOnce,
813 }
814 }
815}
816
817impl<'tcx> Stable<'tcx> for ty::SubtypePredicate<'tcx> {
818 type T = crate::ty::SubtypePredicate;
819
820 fn stable<'cx>(
821 &self,
822 tables: &mut Tables<'cx, BridgeTys>,
823 cx: &CompilerCtxt<'cx, BridgeTys>,
824 ) -> Self::T {
825 let ty::SubtypePredicate { a, b, a_is_expected: _ } = self;
826 crate::ty::SubtypePredicate { a: a.stable(tables, cx), b: b.stable(tables, cx) }
827 }
828}
829
830impl<'tcx> Stable<'tcx> for ty::CoercePredicate<'tcx> {
831 type T = crate::ty::CoercePredicate;
832
833 fn stable<'cx>(
834 &self,
835 tables: &mut Tables<'cx, BridgeTys>,
836 cx: &CompilerCtxt<'cx, BridgeTys>,
837 ) -> Self::T {
838 let ty::CoercePredicate { a, b } = self;
839 crate::ty::CoercePredicate { a: a.stable(tables, cx), b: b.stable(tables, cx) }
840 }
841}
842
843impl<'tcx> Stable<'tcx> for ty::TraitPredicate<'tcx> {
844 type T = crate::ty::TraitPredicate;
845
846 fn stable<'cx>(
847 &self,
848 tables: &mut Tables<'cx, BridgeTys>,
849 cx: &CompilerCtxt<'cx, BridgeTys>,
850 ) -> Self::T {
851 let ty::TraitPredicate { trait_ref, polarity } = self;
852 crate::ty::TraitPredicate {
853 trait_ref: trait_ref.stable(tables, cx),
854 polarity: polarity.stable(tables, cx),
855 }
856 }
857}
858
859impl<'tcx, T> Stable<'tcx> for ty::OutlivesPredicate<'tcx, T>
860where
861 T: Stable<'tcx>,
862{
863 type T = crate::ty::OutlivesPredicate<T::T, Region>;
864
865 fn stable<'cx>(
866 &self,
867 tables: &mut Tables<'cx, BridgeTys>,
868 cx: &CompilerCtxt<'cx, BridgeTys>,
869 ) -> Self::T {
870 let ty::OutlivesPredicate(a, b) = self;
871 crate::ty::OutlivesPredicate(a.stable(tables, cx), b.stable(tables, cx))
872 }
873}
874
875impl<'tcx> Stable<'tcx> for ty::ProjectionPredicate<'tcx> {
876 type T = crate::ty::ProjectionPredicate;
877
878 fn stable<'cx>(
879 &self,
880 tables: &mut Tables<'cx, BridgeTys>,
881 cx: &CompilerCtxt<'cx, BridgeTys>,
882 ) -> Self::T {
883 let ty::ProjectionPredicate { projection_term, term } = self;
884 crate::ty::ProjectionPredicate {
885 projection_term: projection_term.stable(tables, cx),
886 term: term.kind().stable(tables, cx),
887 }
888 }
889}
890
891impl<'tcx> Stable<'tcx> for ty::ImplPolarity {
892 type T = crate::ty::ImplPolarity;
893
894 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
895 use rustc_middle::ty::ImplPolarity::*;
896 match self {
897 Positive => crate::ty::ImplPolarity::Positive,
898 Negative => crate::ty::ImplPolarity::Negative,
899 Reservation => crate::ty::ImplPolarity::Reservation,
900 }
901 }
902}
903
904impl<'tcx> Stable<'tcx> for ty::PredicatePolarity {
905 type T = crate::ty::PredicatePolarity;
906
907 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
908 use rustc_middle::ty::PredicatePolarity::*;
909 match self {
910 Positive => crate::ty::PredicatePolarity::Positive,
911 Negative => crate::ty::PredicatePolarity::Negative,
912 }
913 }
914}
915
916impl<'tcx> Stable<'tcx> for ty::Region<'tcx> {
917 type T = crate::ty::Region;
918
919 fn stable<'cx>(
920 &self,
921 tables: &mut Tables<'cx, BridgeTys>,
922 cx: &CompilerCtxt<'cx, BridgeTys>,
923 ) -> Self::T {
924 Region { kind: self.kind().stable(tables, cx) }
925 }
926}
927
928impl<'tcx> Stable<'tcx> for ty::RegionKind<'tcx> {
929 type T = crate::ty::RegionKind;
930
931 fn stable<'cx>(
932 &self,
933 tables: &mut Tables<'cx, BridgeTys>,
934 cx: &CompilerCtxt<'cx, BridgeTys>,
935 ) -> Self::T {
936 use crate::ty::{BoundRegion, EarlyParamRegion, RegionKind};
937 match self {
938 ty::ReEarlyParam(early_reg) => RegionKind::ReEarlyParam(EarlyParamRegion {
939 index: early_reg.index,
940 name: early_reg.name.to_string(),
941 }),
942 ty::ReBound(ty::BoundVarIndexKind::Bound(db_index), bound_reg) => RegionKind::ReBound(
943 db_index.as_u32(),
944 BoundRegion {
945 var: bound_reg.var.as_u32(),
946 kind: bound_reg.kind.stable(tables, cx),
947 },
948 ),
949 ty::ReStatic => RegionKind::ReStatic,
950 ty::RePlaceholder(place_holder) => RegionKind::RePlaceholder(crate::ty::Placeholder {
951 universe: place_holder.universe.as_u32(),
952 bound: BoundRegion {
953 var: place_holder.bound.var.as_u32(),
954 kind: place_holder.bound.kind.stable(tables, cx),
955 },
956 }),
957 ty::ReErased => RegionKind::ReErased,
958 _ => {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("{0:?}", self)));
}unreachable!("{self:?}"),
959 }
960 }
961}
962
963impl<'tcx> Stable<'tcx> for ty::Instance<'tcx> {
964 type T = crate::mir::mono::Instance;
965
966 fn stable<'cx>(
967 &self,
968 tables: &mut Tables<'cx, BridgeTys>,
969 cx: &CompilerCtxt<'cx, BridgeTys>,
970 ) -> Self::T {
971 let def = tables.instance_def(cx.lift(*self));
972 let kind = match self.def {
973 ty::InstanceKind::Item(..) => crate::mir::mono::InstanceKind::Item,
974 ty::InstanceKind::Intrinsic(..) => crate::mir::mono::InstanceKind::Intrinsic,
975 ty::InstanceKind::LlvmIntrinsic(..) => crate::mir::mono::InstanceKind::LlvmIntrinsic,
976 ty::InstanceKind::Virtual(_def_id, idx) => {
977 crate::mir::mono::InstanceKind::Virtual { idx }
978 }
979 ty::InstanceKind::Shim(..) => crate::mir::mono::InstanceKind::Shim,
980 };
981 crate::mir::mono::Instance { def, kind }
982 }
983}
984
985impl<'tcx> Stable<'tcx> for ty::Variance {
986 type T = crate::mir::Variance;
987 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
988 match self {
989 ty::Bivariant => crate::mir::Variance::Bivariant,
990 ty::Contravariant => crate::mir::Variance::Contravariant,
991 ty::Covariant => crate::mir::Variance::Covariant,
992 ty::Invariant => crate::mir::Variance::Invariant,
993 }
994 }
995}
996
997impl<'tcx> Stable<'tcx> for ty::Movability {
998 type T = crate::ty::Movability;
999
1000 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
1001 match self {
1002 ty::Movability::Static => crate::ty::Movability::Static,
1003 ty::Movability::Movable => crate::ty::Movability::Movable,
1004 }
1005 }
1006}
1007
1008impl<'tcx> Stable<'tcx> for rustc_abi::ExternAbi {
1009 type T = crate::ty::Abi;
1010
1011 fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) -> Self::T {
1012 use rustc_abi::ExternAbi;
1013
1014 use crate::ty::Abi;
1015 match *self {
1016 ExternAbi::Rust => Abi::Rust,
1017 ExternAbi::C { unwind } => Abi::C { unwind },
1018 ExternAbi::Cdecl { unwind } => Abi::Cdecl { unwind },
1019 ExternAbi::Stdcall { unwind } => Abi::Stdcall { unwind },
1020 ExternAbi::Fastcall { unwind } => Abi::Fastcall { unwind },
1021 ExternAbi::Vectorcall { unwind } => Abi::Vectorcall { unwind },
1022 ExternAbi::Thiscall { unwind } => Abi::Thiscall { unwind },
1023 ExternAbi::Aapcs { unwind } => Abi::Aapcs { unwind },
1024 ExternAbi::Win64 { unwind } => Abi::Win64 { unwind },
1025 ExternAbi::SysV64 { unwind } => Abi::SysV64 { unwind },
1026 ExternAbi::PtxKernel => Abi::PtxKernel,
1027 ExternAbi::GpuKernel => Abi::GpuKernel,
1028 ExternAbi::Msp430Interrupt => Abi::Msp430Interrupt,
1029 ExternAbi::X86Interrupt => Abi::X86Interrupt,
1030 ExternAbi::EfiApi => Abi::EfiApi,
1031 ExternAbi::AvrInterrupt => Abi::AvrInterrupt,
1032 ExternAbi::AvrNonBlockingInterrupt => Abi::AvrNonBlockingInterrupt,
1033 ExternAbi::CmseNonSecureCall => Abi::CCmseNonSecureCall,
1034 ExternAbi::CmseNonSecureEntry => Abi::CCmseNonSecureEntry,
1035 ExternAbi::System { unwind } => Abi::System { unwind },
1036 ExternAbi::RustCall => Abi::RustCall,
1037 ExternAbi::Unadjusted => Abi::Unadjusted,
1038 ExternAbi::RustCold => Abi::RustCold,
1039 ExternAbi::RustPreserveNone => Abi::RustPreserveNone,
1040 ExternAbi::RustTail => Abi::RustTail,
1041 ExternAbi::RustInvalid => Abi::RustInvalid,
1042 ExternAbi::RiscvInterruptM => Abi::RiscvInterruptM,
1043 ExternAbi::RiscvInterruptS => Abi::RiscvInterruptS,
1044 ExternAbi::Custom => Abi::Custom,
1045 ExternAbi::Swift => Abi::Swift,
1046 }
1047 }
1048}
1049
1050impl<'tcx> Stable<'tcx> for rustc_session::cstore::ForeignModule {
1051 type T = crate::ty::ForeignModule;
1052
1053 fn stable<'cx>(
1054 &self,
1055 tables: &mut Tables<'cx, BridgeTys>,
1056 cx: &CompilerCtxt<'cx, BridgeTys>,
1057 ) -> Self::T {
1058 crate::ty::ForeignModule {
1059 def_id: tables.foreign_module_def(self.def_id),
1060 abi: self.abi.stable(tables, cx),
1061 }
1062 }
1063}
1064
1065impl<'tcx> Stable<'tcx> for ty::AssocKind {
1066 type T = crate::ty::AssocKind;
1067
1068 fn stable<'cx>(
1069 &self,
1070 tables: &mut Tables<'cx, BridgeTys>,
1071 cx: &CompilerCtxt<'cx, BridgeTys>,
1072 ) -> Self::T {
1073 use crate::ty::{AssocKind, AssocTypeData};
1074 match *self {
1075 ty::AssocKind::Const { name, .. } => AssocKind::Const { name: name.to_string() },
1076 ty::AssocKind::Fn { name, has_self } => {
1077 AssocKind::Fn { name: name.to_string(), has_self }
1078 }
1079 ty::AssocKind::Type { data } => AssocKind::Type {
1080 data: match data {
1081 ty::AssocTypeData::Normal(name) => AssocTypeData::Normal(name.to_string()),
1082 ty::AssocTypeData::Rpitit(rpitit) => {
1083 AssocTypeData::Rpitit(rpitit.stable(tables, cx))
1084 }
1085 },
1086 },
1087 }
1088 }
1089}
1090
1091impl<'tcx> Stable<'tcx> for ty::AssocContainer {
1092 type T = crate::ty::AssocContainer;
1093
1094 fn stable(
1095 &self,
1096 tables: &mut Tables<'_, BridgeTys>,
1097 _: &CompilerCtxt<'_, BridgeTys>,
1098 ) -> Self::T {
1099 use crate::ty::AssocContainer;
1100 match self {
1101 ty::AssocContainer::Trait => AssocContainer::Trait,
1102 ty::AssocContainer::InherentImpl => AssocContainer::InherentImpl,
1103 ty::AssocContainer::TraitImpl(trait_item_id) => {
1104 AssocContainer::TraitImpl(tables.assoc_def(trait_item_id.unwrap()))
1105 }
1106 }
1107 }
1108}
1109
1110impl<'tcx> Stable<'tcx> for ty::AssocItem {
1111 type T = crate::ty::AssocItem;
1112
1113 fn stable<'cx>(
1114 &self,
1115 tables: &mut Tables<'cx, BridgeTys>,
1116 cx: &CompilerCtxt<'cx, BridgeTys>,
1117 ) -> Self::T {
1118 crate::ty::AssocItem {
1119 def_id: tables.assoc_def(self.def_id),
1120 kind: self.kind.stable(tables, cx),
1121 container: self.container.stable(tables, cx),
1122 }
1123 }
1124}
1125
1126impl<'tcx> Stable<'tcx> for ty::ImplTraitInTraitData {
1127 type T = crate::ty::ImplTraitInTraitData;
1128
1129 fn stable<'cx>(
1130 &self,
1131 tables: &mut Tables<'cx, BridgeTys>,
1132 _: &CompilerCtxt<'cx, BridgeTys>,
1133 ) -> Self::T {
1134 use crate::ty::ImplTraitInTraitData;
1135 match self {
1136 ty::ImplTraitInTraitData::Trait { fn_def_id, opaque_def_id } => {
1137 ImplTraitInTraitData::Trait {
1138 fn_def_id: tables.fn_def(*fn_def_id),
1139 opaque_def_id: tables.opaque_def(*opaque_def_id),
1140 }
1141 }
1142 ty::ImplTraitInTraitData::Impl { fn_def_id } => {
1143 ImplTraitInTraitData::Impl { fn_def_id: tables.fn_def(*fn_def_id) }
1144 }
1145 }
1146 }
1147}
1148
1149impl<'tcx> Stable<'tcx> for rustc_middle::ty::util::Discr<'tcx> {
1150 type T = crate::ty::Discr;
1151
1152 fn stable<'cx>(
1153 &self,
1154 tables: &mut Tables<'cx, BridgeTys>,
1155 cx: &CompilerCtxt<'cx, BridgeTys>,
1156 ) -> Self::T {
1157 crate::ty::Discr { val: self.val, ty: self.ty.stable(tables, cx) }
1158 }
1159}
1160
1161impl<'tcx> Stable<'tcx> for rustc_middle::ty::VtblEntry<'tcx> {
1162 type T = crate::ty::VtblEntry;
1163
1164 fn stable<'cx>(
1165 &self,
1166 tables: &mut Tables<'cx, BridgeTys>,
1167 cx: &CompilerCtxt<'cx, BridgeTys>,
1168 ) -> Self::T {
1169 use crate::ty::VtblEntry;
1170 match self {
1171 ty::VtblEntry::MetadataDropInPlace => VtblEntry::MetadataDropInPlace,
1172 ty::VtblEntry::MetadataSize => VtblEntry::MetadataSize,
1173 ty::VtblEntry::MetadataAlign => VtblEntry::MetadataAlign,
1174 ty::VtblEntry::Vacant => VtblEntry::Vacant,
1175 ty::VtblEntry::Method(instance) => VtblEntry::Method(instance.stable(tables, cx)),
1176 ty::VtblEntry::TraitVPtr(trait_ref) => {
1177 VtblEntry::TraitVPtr(trait_ref.stable(tables, cx))
1178 }
1179 }
1180 }
1181}