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