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) -> 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<
51 ty::BoundVariableKind<'tcx>,
52 &'tcx List<ty::BoundVariableKind<'tcx>>,
53 >;
54
55 fn mk_place_elems(self, v: &[mir::PlaceElem<'tcx>]) -> &'tcx List<mir::PlaceElem<'tcx>>;
56
57 fn adt_def(self, def_id: rustc_hir::def_id::DefId) -> ty::AdtDef<'tcx>;
58
59 fn mk_patterns_from_iter<I, T>(self, iter: I) -> T::Output
60 where
61 I: Iterator<Item = T>,
62 T: ty::CollectAndApply<ty::Pattern<'tcx>, &'tcx List<ty::Pattern<'tcx>>>;
63}
64
65#[doc(hidden)]
71#[cfg_attr(not(feature = "rustc_internal"), allow(unreachable_pub))]
72pub trait Stable<'tcx>: PointeeSized {
73 type T;
75 fn stable<'cx>(
77 &self,
78 tables: &mut Tables<'cx, BridgeTys>,
79 cx: &CompilerCtxt<'cx, BridgeTys>,
80 ) -> Self::T;
81}
82
83#[doc(hidden)]
91#[cfg_attr(not(feature = "rustc_internal"), allow(unreachable_pub))]
92pub trait RustcInternal {
93 type T<'tcx>;
94 fn internal<'tcx>(
95 &self,
96 tables: &mut Tables<'_, BridgeTys>,
97 tcx: impl InternalCx<'tcx>,
98 ) -> Self::T<'tcx>;
99}
100
101pub(crate) fn new_item_kind(kind: DefKind) -> ItemKind {
102 match kind {
103 DefKind::Mod
104 | DefKind::Struct
105 | DefKind::Union
106 | DefKind::Enum
107 | DefKind::Variant
108 | DefKind::Trait
109 | DefKind::TyAlias
110 | DefKind::ForeignTy
111 | DefKind::TraitAlias
112 | DefKind::AssocTy
113 | DefKind::TyParam
114 | DefKind::ConstParam
115 | DefKind::Macro(_)
116 | DefKind::ExternCrate
117 | DefKind::Use
118 | DefKind::ForeignMod
119 | DefKind::OpaqueTy
120 | DefKind::Field
121 | DefKind::LifetimeParam
122 | DefKind::Impl { .. }
123 | DefKind::GlobalAsm
124 | DefKind::TestBinderConstraints => {
125 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("Not a valid item kind: {0:?}", kind)));
};unreachable!("Not a valid item kind: {kind:?}");
126 }
127 DefKind::Closure | DefKind::AssocFn | DefKind::Fn | DefKind::SyntheticCoroutineBody => {
128 ItemKind::Fn
129 }
130 DefKind::Const { .. } | DefKind::AssocConst { .. } | DefKind::AnonConst => ItemKind::Const,
131 DefKind::Static { .. } => ItemKind::Static,
132 DefKind::Ctor(_, rustc_hir::def::CtorKind::Const) => ItemKind::Ctor(CtorKind::Const),
133 DefKind::Ctor(_, rustc_hir::def::CtorKind::Fn) => ItemKind::Ctor(CtorKind::Fn),
134 }
135}