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