From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_middle/src/ty/parameterized.rs | 119 ++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 compiler/rustc_middle/src/ty/parameterized.rs (limited to 'compiler/rustc_middle/src/ty/parameterized.rs') diff --git a/compiler/rustc_middle/src/ty/parameterized.rs b/compiler/rustc_middle/src/ty/parameterized.rs new file mode 100644 index 000000000..e189ee2fc --- /dev/null +++ b/compiler/rustc_middle/src/ty/parameterized.rs @@ -0,0 +1,119 @@ +use rustc_hir::def_id::DefId; +use rustc_index::vec::{Idx, IndexVec}; + +use crate::middle::exported_symbols::ExportedSymbol; +use crate::mir::Body; +use crate::ty::abstract_const::Node; +use crate::ty::{ + self, Const, FnSig, GeneratorDiagnosticData, GenericPredicates, Predicate, TraitRef, Ty, +}; + +pub trait ParameterizedOverTcx: 'static { + #[allow(unused_lifetimes)] + type Value<'tcx>; +} + +impl ParameterizedOverTcx for &'static [T] { + type Value<'tcx> = &'tcx [T::Value<'tcx>]; +} + +impl ParameterizedOverTcx for Option { + type Value<'tcx> = Option>; +} + +impl ParameterizedOverTcx for (A, B) { + type Value<'tcx> = (A::Value<'tcx>, B::Value<'tcx>); +} + +impl ParameterizedOverTcx for IndexVec { + type Value<'tcx> = IndexVec>; +} + +impl ParameterizedOverTcx for ty::Binder<'static, T> { + type Value<'tcx> = ty::Binder<'tcx, T::Value<'tcx>>; +} + +#[macro_export] +macro_rules! trivially_parameterized_over_tcx { + ($($ty:ty),+ $(,)?) => { + $( + impl $crate::ty::ParameterizedOverTcx for $ty { + #[allow(unused_lifetimes)] + type Value<'tcx> = $ty; + } + )* + } +} + +trivially_parameterized_over_tcx! { + usize, + (), + u32, + std::string::String, + crate::metadata::ModChild, + crate::middle::codegen_fn_attrs::CodegenFnAttrs, + crate::middle::exported_symbols::SymbolExportInfo, + crate::mir::ConstQualifs, + ty::Generics, + ty::ImplPolarity, + ty::ReprOptions, + ty::TraitDef, + ty::Visibility, + ty::adjustment::CoerceUnsizedInfo, + ty::fast_reject::SimplifiedTypeGen, + rustc_ast::Attribute, + rustc_ast::MacArgs, + rustc_attr::ConstStability, + rustc_attr::Deprecation, + rustc_attr::Stability, + rustc_hir::Constness, + rustc_hir::Defaultness, + rustc_hir::GeneratorKind, + rustc_hir::IsAsync, + rustc_hir::LangItem, + rustc_hir::def::DefKind, + rustc_hir::def_id::DefIndex, + rustc_hir::definitions::DefKey, + rustc_index::bit_set::FiniteBitSet, + rustc_session::cstore::ForeignModule, + rustc_session::cstore::LinkagePreference, + rustc_session::cstore::NativeLib, + rustc_span::DebuggerVisualizerFile, + rustc_span::ExpnData, + rustc_span::ExpnHash, + rustc_span::ExpnId, + rustc_span::SourceFile, + rustc_span::Span, + rustc_span::Symbol, + rustc_span::def_id::DefPathHash, + rustc_span::hygiene::SyntaxContextData, + rustc_span::symbol::Ident, + rustc_type_ir::Variance, +} + +// HACK(compiler-errors): This macro rule can only take an ident, +// not a path, due to parsing ambiguity reasons. That means we gotta +// import all of these types above. +#[macro_export] +macro_rules! parameterized_over_tcx { + ($($ident:ident),+ $(,)?) => { + $( + impl $crate::ty::ParameterizedOverTcx for $ident<'static> { + type Value<'tcx> = $ident<'tcx>; + } + )* + } +} + +parameterized_over_tcx! { + Ty, + FnSig, + GenericPredicates, + TraitRef, + Const, + Predicate, + GeneratorDiagnosticData, + Body, + Node, + ExportedSymbol, +} -- cgit v1.2.3