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