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