rustc_middle/ty/
parameterized.rs

1use std::hash::Hash;
2
3use rustc_data_structures::unord::UnordMap;
4use rustc_hir::def_id::DefIndex;
5use rustc_index::{Idx, IndexVec};
6use rustc_span::Symbol;
7
8use crate::ty;
9
10pub trait ParameterizedOverTcx: 'static {
11    type Value<'tcx>;
12}
13
14impl<T: ParameterizedOverTcx> ParameterizedOverTcx for &'static [T] {
15    type Value<'tcx> = &'tcx [T::Value<'tcx>];
16}
17
18impl<T: ParameterizedOverTcx> ParameterizedOverTcx for Option<T> {
19    type Value<'tcx> = Option<T::Value<'tcx>>;
20}
21
22impl<A: ParameterizedOverTcx, B: ParameterizedOverTcx> ParameterizedOverTcx for (A, B) {
23    type Value<'tcx> = (A::Value<'tcx>, B::Value<'tcx>);
24}
25
26impl<T: ParameterizedOverTcx> ParameterizedOverTcx for Vec<T> {
27    type Value<'tcx> = Vec<T::Value<'tcx>>;
28}
29
30impl<I: Idx + 'static, T: ParameterizedOverTcx> ParameterizedOverTcx for IndexVec<I, T> {
31    type Value<'tcx> = IndexVec<I, T::Value<'tcx>>;
32}
33
34impl<I: Hash + Eq + 'static, T: ParameterizedOverTcx> ParameterizedOverTcx for UnordMap<I, T> {
35    type Value<'tcx> = UnordMap<I, T::Value<'tcx>>;
36}
37
38impl<T: ParameterizedOverTcx> ParameterizedOverTcx for ty::Binder<'static, T> {
39    type Value<'tcx> = ty::Binder<'tcx, T::Value<'tcx>>;
40}
41
42impl<T: ParameterizedOverTcx> ParameterizedOverTcx for ty::EarlyBinder<'static, T> {
43    type Value<'tcx> = ty::EarlyBinder<'tcx, T::Value<'tcx>>;
44}
45
46#[macro_export]
47macro_rules! trivially_parameterized_over_tcx {
48    ($($ty:ty),+ $(,)?) => {
49        $(
50            impl $crate::ty::ParameterizedOverTcx for $ty {
51                #[allow(unused_lifetimes)]
52                type Value<'tcx> = $ty;
53            }
54        )*
55    }
56}
57
58trivially_parameterized_over_tcx! {
59    usize,
60    (),
61    u32,
62    u64,
63    bool,
64    std::string::String,
65    crate::metadata::ModChild,
66    crate::middle::codegen_fn_attrs::CodegenFnAttrs,
67    crate::middle::debugger_visualizer::DebuggerVisualizerFile,
68    crate::middle::exported_symbols::SymbolExportInfo,
69    crate::middle::lib_features::FeatureStability,
70    crate::middle::resolve_bound_vars::ObjectLifetimeDefault,
71    crate::mir::ConstQualifs,
72    ty::AsyncDestructor,
73    ty::AssocItemContainer,
74    ty::Asyncness,
75    ty::AnonConstKind,
76    ty::DeducedParamAttrs,
77    ty::Destructor,
78    ty::Generics,
79    ty::ImplPolarity,
80    ty::ImplTraitInTraitData,
81    ty::ReprOptions,
82    ty::TraitDef,
83    ty::UnusedGenericParams,
84    ty::Visibility<DefIndex>,
85    ty::adjustment::CoerceUnsizedInfo,
86    ty::fast_reject::SimplifiedType,
87    ty::IntrinsicDef,
88    rustc_ast::Attribute,
89    rustc_ast::DelimArgs,
90    rustc_attr_data_structures::StrippedCfgItem<rustc_hir::def_id::DefIndex>,
91    rustc_attr_data_structures::ConstStability,
92    rustc_attr_data_structures::DefaultBodyStability,
93    rustc_attr_data_structures::Deprecation,
94    rustc_attr_data_structures::Stability,
95    rustc_hir::Constness,
96    rustc_hir::Defaultness,
97    rustc_hir::Safety,
98    rustc_hir::CoroutineKind,
99    rustc_hir::IsAsync,
100    rustc_hir::LangItem,
101    rustc_hir::def::DefKind,
102    rustc_hir::def::DocLinkResMap,
103    rustc_hir::def_id::DefId,
104    rustc_hir::def_id::DefIndex,
105    rustc_hir::definitions::DefKey,
106    rustc_hir::OpaqueTyOrigin<rustc_hir::def_id::DefId>,
107    rustc_hir::PreciseCapturingArgKind<Symbol, Symbol>,
108    rustc_index::bit_set::DenseBitSet<u32>,
109    rustc_index::bit_set::FiniteBitSet<u32>,
110    rustc_session::cstore::ForeignModule,
111    rustc_session::cstore::LinkagePreference,
112    rustc_session::cstore::NativeLib,
113    rustc_session::config::TargetModifier,
114    rustc_span::ExpnData,
115    rustc_span::ExpnHash,
116    rustc_span::ExpnId,
117    rustc_span::SourceFile,
118    rustc_span::Span,
119    rustc_span::Symbol,
120    rustc_span::def_id::DefPathHash,
121    rustc_span::hygiene::SyntaxContextKey,
122    rustc_span::Ident,
123    rustc_type_ir::Variance,
124    rustc_hir::Attribute,
125}
126
127// HACK(compiler-errors): This macro rule can only take a fake path,
128// not a real, due to parsing ambiguity reasons.
129#[macro_export]
130macro_rules! parameterized_over_tcx {
131    ($($($fake_path:ident)::+),+ $(,)?) => {
132        $(
133            impl $crate::ty::ParameterizedOverTcx for $($fake_path)::+<'static> {
134                type Value<'tcx> = $($fake_path)::+<'tcx>;
135            }
136        )*
137    }
138}
139
140parameterized_over_tcx! {
141    crate::middle::exported_symbols::ExportedSymbol,
142    crate::mir::Body,
143    crate::mir::CoroutineLayout,
144    crate::mir::interpret::ConstAllocation,
145    ty::Ty,
146    ty::FnSig,
147    ty::GenericPredicates,
148    ty::ConstConditions,
149    ty::TraitRef,
150    ty::Const,
151    ty::Predicate,
152    ty::Clause,
153    ty::ClauseKind,
154    ty::ImplTraitHeader,
155}