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