]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_middle/src/ty/parameterized.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / compiler / rustc_middle / src / ty / parameterized.rs
CommitLineData
2b03887a 1use rustc_data_structures::fx::FxHashMap;
f2b60f7d 2use rustc_hir::def_id::{DefId, DefIndex};
923072b8
FG
3use rustc_index::vec::{Idx, IndexVec};
4
5use crate::middle::exported_symbols::ExportedSymbol;
6use crate::mir::Body;
064997fb 7use crate::ty::abstract_const::Node;
923072b8
FG
8use crate::ty::{
9 self, Const, FnSig, GeneratorDiagnosticData, GenericPredicates, Predicate, TraitRef, Ty,
10};
11
12pub trait ParameterizedOverTcx: 'static {
13 #[allow(unused_lifetimes)]
14 type Value<'tcx>;
15}
16
17impl<T: ParameterizedOverTcx> ParameterizedOverTcx for &'static [T] {
18 type Value<'tcx> = &'tcx [T::Value<'tcx>];
19}
20
21impl<T: ParameterizedOverTcx> ParameterizedOverTcx for Option<T> {
22 type Value<'tcx> = Option<T::Value<'tcx>>;
23}
24
25impl<A: ParameterizedOverTcx, B: ParameterizedOverTcx> ParameterizedOverTcx for (A, B) {
26 type Value<'tcx> = (A::Value<'tcx>, B::Value<'tcx>);
27}
28
29impl<I: Idx + 'static, T: ParameterizedOverTcx> ParameterizedOverTcx for IndexVec<I, T> {
30 type Value<'tcx> = IndexVec<I, T::Value<'tcx>>;
31}
32
2b03887a
FG
33impl<I: 'static, T: ParameterizedOverTcx> ParameterizedOverTcx for FxHashMap<I, T> {
34 type Value<'tcx> = FxHashMap<I, T::Value<'tcx>>;
35}
36
923072b8
FG
37impl<T: ParameterizedOverTcx> ParameterizedOverTcx for ty::Binder<'static, T> {
38 type Value<'tcx> = ty::Binder<'tcx, T::Value<'tcx>>;
39}
40
41#[macro_export]
42macro_rules! trivially_parameterized_over_tcx {
43 ($($ty:ty),+ $(,)?) => {
44 $(
45 impl $crate::ty::ParameterizedOverTcx for $ty {
46 #[allow(unused_lifetimes)]
47 type Value<'tcx> = $ty;
48 }
49 )*
50 }
51}
52
53trivially_parameterized_over_tcx! {
54 usize,
55 (),
56 u32,
57 std::string::String,
58 crate::metadata::ModChild,
59 crate::middle::codegen_fn_attrs::CodegenFnAttrs,
60 crate::middle::exported_symbols::SymbolExportInfo,
f2b60f7d 61 crate::middle::resolve_lifetime::ObjectLifetimeDefault,
923072b8 62 crate::mir::ConstQualifs,
f2b60f7d 63 ty::AssocItemContainer,
2b03887a 64 ty::DeducedParamAttrs,
923072b8
FG
65 ty::Generics,
66 ty::ImplPolarity,
67 ty::ReprOptions,
68 ty::TraitDef,
f2b60f7d 69 ty::Visibility<DefIndex>,
923072b8
FG
70 ty::adjustment::CoerceUnsizedInfo,
71 ty::fast_reject::SimplifiedTypeGen<DefId>,
72 rustc_ast::Attribute,
73 rustc_ast::MacArgs,
74 rustc_attr::ConstStability,
f2b60f7d 75 rustc_attr::DefaultBodyStability,
923072b8
FG
76 rustc_attr::Deprecation,
77 rustc_attr::Stability,
78 rustc_hir::Constness,
79 rustc_hir::Defaultness,
80 rustc_hir::GeneratorKind,
81 rustc_hir::IsAsync,
82 rustc_hir::LangItem,
83 rustc_hir::def::DefKind,
84 rustc_hir::def_id::DefIndex,
85 rustc_hir::definitions::DefKey,
2b03887a 86 rustc_index::bit_set::BitSet<u32>,
923072b8
FG
87 rustc_index::bit_set::FiniteBitSet<u32>,
88 rustc_session::cstore::ForeignModule,
89 rustc_session::cstore::LinkagePreference,
90 rustc_session::cstore::NativeLib,
91 rustc_span::DebuggerVisualizerFile,
92 rustc_span::ExpnData,
93 rustc_span::ExpnHash,
94 rustc_span::ExpnId,
95 rustc_span::SourceFile,
96 rustc_span::Span,
97 rustc_span::Symbol,
98 rustc_span::def_id::DefPathHash,
99 rustc_span::hygiene::SyntaxContextData,
100 rustc_span::symbol::Ident,
101 rustc_type_ir::Variance,
102}
103
104// HACK(compiler-errors): This macro rule can only take an ident,
105// not a path, due to parsing ambiguity reasons. That means we gotta
106// import all of these types above.
107#[macro_export]
108macro_rules! parameterized_over_tcx {
109 ($($ident:ident),+ $(,)?) => {
110 $(
111 impl $crate::ty::ParameterizedOverTcx for $ident<'static> {
112 type Value<'tcx> = $ident<'tcx>;
113 }
114 )*
115 }
116}
117
118parameterized_over_tcx! {
119 Ty,
120 FnSig,
121 GenericPredicates,
122 TraitRef,
123 Const,
124 Predicate,
125 GeneratorDiagnosticData,
126 Body,
127 Node,
128 ExportedSymbol,
129}