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