]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_middle/src/ty/parameterized.rs
Rollup merge of #97210 - Milo123459:clippy-args, r=jyn514
[rust.git] / compiler / rustc_middle / src / ty / parameterized.rs
1 use rustc_hir::def_id::DefId;
2 use rustc_index::vec::{Idx, IndexVec};
3
4 use crate::middle::exported_symbols::ExportedSymbol;
5 use crate::mir::Body;
6 use crate::thir::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::mir::ConstQualifs,
57     ty::Generics,
58     ty::ImplPolarity,
59     ty::ReprOptions,
60     ty::TraitDef,
61     ty::Visibility,
62     ty::adjustment::CoerceUnsizedInfo,
63     ty::fast_reject::SimplifiedTypeGen<DefId>,
64     rustc_ast::Attribute,
65     rustc_ast::MacArgs,
66     rustc_attr::ConstStability,
67     rustc_attr::Deprecation,
68     rustc_attr::Stability,
69     rustc_hir::Constness,
70     rustc_hir::Defaultness,
71     rustc_hir::GeneratorKind,
72     rustc_hir::IsAsync,
73     rustc_hir::LangItem,
74     rustc_hir::def::DefKind,
75     rustc_hir::def_id::DefIndex,
76     rustc_hir::definitions::DefKey,
77     rustc_index::bit_set::FiniteBitSet<u32>,
78     rustc_session::cstore::ForeignModule,
79     rustc_session::cstore::LinkagePreference,
80     rustc_session::cstore::NativeLib,
81     rustc_span::DebuggerVisualizerFile,
82     rustc_span::ExpnData,
83     rustc_span::ExpnHash,
84     rustc_span::ExpnId,
85     rustc_span::SourceFile,
86     rustc_span::Span,
87     rustc_span::Symbol,
88     rustc_span::def_id::DefPathHash,
89     rustc_span::hygiene::SyntaxContextData,
90     rustc_span::symbol::Ident,
91     rustc_type_ir::Variance,
92 }
93
94 // HACK(compiler-errors): This macro rule can only take an ident,
95 // not a path, due to parsing ambiguity reasons. That means we gotta
96 // import all of these types above.
97 #[macro_export]
98 macro_rules! parameterized_over_tcx {
99     ($($ident:ident),+ $(,)?) => {
100         $(
101             impl $crate::ty::ParameterizedOverTcx for $ident<'static> {
102                 type Value<'tcx> = $ident<'tcx>;
103             }
104         )*
105     }
106 }
107
108 parameterized_over_tcx! {
109     Ty,
110     FnSig,
111     GenericPredicates,
112     TraitRef,
113     Const,
114     Predicate,
115     GeneratorDiagnosticData,
116     Body,
117     Node,
118     ExportedSymbol,
119 }