rustc_public/unstable/
mod.rs1use std::marker::PointeeSized;
8
9use rustc_hir::def::DefKind;
10use rustc_middle::ty::{List, Ty, TyCtxt};
11use rustc_middle::{mir, ty};
12use rustc_public_bridge::Tables;
13use rustc_public_bridge::context::CompilerCtxt;
14
15use super::compiler_interface::BridgeTys;
16use crate::{CtorKind, ItemKind};
17
18pub(crate) mod convert;
19mod internal_cx;
20
21pub trait InternalCx<'tcx>: Copy + Clone {
26    fn tcx(self) -> TyCtxt<'tcx>;
27
28    fn lift<T: ty::Lift<TyCtxt<'tcx>>>(self, value: T) -> Option<T::Lifted>;
29
30    fn mk_args_from_iter<I, T>(self, iter: I) -> T::Output
31    where
32        I: Iterator<Item = T>,
33        T: ty::CollectAndApply<ty::GenericArg<'tcx>, ty::GenericArgsRef<'tcx>>;
34
35    fn mk_pat(self, v: ty::PatternKind<'tcx>) -> ty::Pattern<'tcx>;
36
37    fn mk_poly_existential_predicates(
38        self,
39        eps: &[ty::PolyExistentialPredicate<'tcx>],
40    ) -> &'tcx List<ty::PolyExistentialPredicate<'tcx>>;
41
42    fn mk_type_list(self, v: &[Ty<'tcx>]) -> &'tcx List<Ty<'tcx>>;
43
44    fn lifetimes_re_erased(self) -> ty::Region<'tcx>;
45
46    fn mk_bound_variable_kinds_from_iter<I, T>(self, iter: I) -> T::Output
47    where
48        I: Iterator<Item = T>,
49        T: ty::CollectAndApply<ty::BoundVariableKind, &'tcx List<ty::BoundVariableKind>>;
50
51    fn mk_place_elems(self, v: &[mir::PlaceElem<'tcx>]) -> &'tcx List<mir::PlaceElem<'tcx>>;
52
53    fn adt_def(self, def_id: rustc_hir::def_id::DefId) -> ty::AdtDef<'tcx>;
54}
55
56#[doc(hidden)]
62pub trait Stable<'tcx>: PointeeSized {
63    type T;
65    fn stable<'cx>(
67        &self,
68        tables: &mut Tables<'cx, BridgeTys>,
69        cx: &CompilerCtxt<'cx, BridgeTys>,
70    ) -> Self::T;
71}
72
73#[doc(hidden)]
81pub trait RustcInternal {
82    type T<'tcx>;
83    fn internal<'tcx>(
84        &self,
85        tables: &mut Tables<'_, BridgeTys>,
86        tcx: impl InternalCx<'tcx>,
87    ) -> Self::T<'tcx>;
88}
89
90pub(crate) fn new_item_kind(kind: DefKind) -> ItemKind {
91    match kind {
92        DefKind::Mod
93        | DefKind::Struct
94        | DefKind::Union
95        | DefKind::Enum
96        | DefKind::Variant
97        | DefKind::Trait
98        | DefKind::TyAlias
99        | DefKind::ForeignTy
100        | DefKind::TraitAlias
101        | DefKind::AssocTy
102        | DefKind::TyParam
103        | DefKind::ConstParam
104        | DefKind::Macro(_)
105        | DefKind::ExternCrate
106        | DefKind::Use
107        | DefKind::ForeignMod
108        | DefKind::OpaqueTy
109        | DefKind::Field
110        | DefKind::LifetimeParam
111        | DefKind::Impl { .. }
112        | DefKind::GlobalAsm => {
113            unreachable!("Not a valid item kind: {kind:?}");
114        }
115        DefKind::Closure | DefKind::AssocFn | DefKind::Fn | DefKind::SyntheticCoroutineBody => {
116            ItemKind::Fn
117        }
118        DefKind::Const | DefKind::InlineConst | DefKind::AssocConst | DefKind::AnonConst => {
119            ItemKind::Const
120        }
121        DefKind::Static { .. } => ItemKind::Static,
122        DefKind::Ctor(_, rustc_hir::def::CtorKind::Const) => ItemKind::Ctor(CtorKind::Const),
123        DefKind::Ctor(_, rustc_hir::def::CtorKind::Fn) => ItemKind::Ctor(CtorKind::Fn),
124    }
125}