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