]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_middle/src/ty/parameterized.rs
Rollup merge of #106383 - Manishearth:ast-docs, r=compiler-errors
[rust.git] / compiler / rustc_middle / src / ty / parameterized.rs
1 use rustc_data_structures::fx::FxHashMap;
2 use rustc_hir::def_id::DefIndex;
3 use rustc_index::vec::{Idx, IndexVec};
4
5 use crate::ty;
6
7 pub trait ParameterizedOverTcx: 'static {
8     type Value<'tcx>;
9 }
10
11 impl<T: ParameterizedOverTcx> ParameterizedOverTcx for &'static [T] {
12     type Value<'tcx> = &'tcx [T::Value<'tcx>];
13 }
14
15 impl<T: ParameterizedOverTcx> ParameterizedOverTcx for Option<T> {
16     type Value<'tcx> = Option<T::Value<'tcx>>;
17 }
18
19 impl<A: ParameterizedOverTcx, B: ParameterizedOverTcx> ParameterizedOverTcx for (A, B) {
20     type Value<'tcx> = (A::Value<'tcx>, B::Value<'tcx>);
21 }
22
23 impl<I: Idx + 'static, T: ParameterizedOverTcx> ParameterizedOverTcx for IndexVec<I, T> {
24     type Value<'tcx> = IndexVec<I, T::Value<'tcx>>;
25 }
26
27 impl<I: 'static, T: ParameterizedOverTcx> ParameterizedOverTcx for FxHashMap<I, T> {
28     type Value<'tcx> = FxHashMap<I, T::Value<'tcx>>;
29 }
30
31 impl<T: ParameterizedOverTcx> ParameterizedOverTcx for ty::Binder<'static, T> {
32     type Value<'tcx> = ty::Binder<'tcx, T::Value<'tcx>>;
33 }
34
35 #[macro_export]
36 macro_rules! trivially_parameterized_over_tcx {
37     ($($ty:ty),+ $(,)?) => {
38         $(
39             impl $crate::ty::ParameterizedOverTcx for $ty {
40                 #[allow(unused_lifetimes)]
41                 type Value<'tcx> = $ty;
42             }
43         )*
44     }
45 }
46
47 trivially_parameterized_over_tcx! {
48     usize,
49     (),
50     u32,
51     std::string::String,
52     crate::metadata::ModChild,
53     crate::middle::codegen_fn_attrs::CodegenFnAttrs,
54     crate::middle::exported_symbols::SymbolExportInfo,
55     crate::middle::resolve_lifetime::ObjectLifetimeDefault,
56     crate::mir::ConstQualifs,
57     ty::AssocItemContainer,
58     ty::DeducedParamAttrs,
59     ty::Generics,
60     ty::ImplPolarity,
61     ty::ReprOptions,
62     ty::TraitDef,
63     ty::Visibility<DefIndex>,
64     ty::adjustment::CoerceUnsizedInfo,
65     ty::fast_reject::SimplifiedType,
66     rustc_ast::Attribute,
67     rustc_ast::DelimArgs,
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::BitSet<u32>,
81     rustc_index::bit_set::FiniteBitSet<u32>,
82     rustc_session::cstore::ForeignModule,
83     rustc_session::cstore::LinkagePreference,
84     rustc_session::cstore::NativeLib,
85     rustc_span::DebuggerVisualizerFile,
86     rustc_span::ExpnData,
87     rustc_span::ExpnHash,
88     rustc_span::ExpnId,
89     rustc_span::SourceFile,
90     rustc_span::Span,
91     rustc_span::Symbol,
92     rustc_span::def_id::DefPathHash,
93     rustc_span::hygiene::SyntaxContextData,
94     rustc_span::symbol::Ident,
95     rustc_type_ir::Variance,
96 }
97
98 // HACK(compiler-errors): This macro rule can only take a fake path,
99 // not a real, due to parsing ambiguity reasons.
100 #[macro_export]
101 macro_rules! parameterized_over_tcx {
102     ($($($fake_path:ident)::+),+ $(,)?) => {
103         $(
104             impl $crate::ty::ParameterizedOverTcx for $($fake_path)::+<'static> {
105                 type Value<'tcx> = $($fake_path)::+<'tcx>;
106             }
107         )*
108     }
109 }
110
111 parameterized_over_tcx! {
112     crate::middle::exported_symbols::ExportedSymbol,
113     crate::mir::Body,
114     ty::Ty,
115     ty::FnSig,
116     ty::GenericPredicates,
117     ty::TraitRef,
118     ty::Const,
119     ty::Predicate,
120     ty::Clause,
121     ty::GeneratorDiagnosticData,
122 }