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