Use a struct instead of a tuple

This commit is contained in:
Oli Scherer 2024-02-10 21:46:44 +00:00
parent 916951efcc
commit 90a43f1406
8 changed files with 19 additions and 10 deletions

View File

@ -1326,7 +1326,7 @@ fn suggest_impl_trait<'tcx>(
fn impl_trait_header( fn impl_trait_header(
tcx: TyCtxt<'_>, tcx: TyCtxt<'_>,
def_id: LocalDefId, def_id: LocalDefId,
) -> Option<(ty::EarlyBinder<ty::TraitRef<'_>>, ty::ImplPolarity)> { ) -> Option<ty::EarlyBinder<ty::ImplTraitHeader<'_>>> {
let icx = ItemCtxt::new(tcx, def_id); let icx = ItemCtxt::new(tcx, def_id);
let item = tcx.hir().expect_item(def_id); let item = tcx.hir().expect_item(def_id);
let impl_ = item.expect_impl(); let impl_ = item.expect_impl();
@ -1336,7 +1336,7 @@ fn impl_trait_header(
.map(|ast_trait_ref| { .map(|ast_trait_ref| {
let selfty = tcx.type_of(def_id).instantiate_identity(); let selfty = tcx.type_of(def_id).instantiate_identity();
let impl_trait_ref = if let Some(ErrorGuaranteed { .. }) = check_impl_constness( let trait_ref = if let Some(ErrorGuaranteed { .. }) = check_impl_constness(
tcx, tcx,
tcx.is_const_trait_impl_raw(def_id.to_def_id()), tcx.is_const_trait_impl_raw(def_id.to_def_id()),
ast_trait_ref, ast_trait_ref,
@ -1362,7 +1362,10 @@ fn impl_trait_header(
} else { } else {
icx.astconv().instantiate_mono_trait_ref(ast_trait_ref, selfty) icx.astconv().instantiate_mono_trait_ref(ast_trait_ref, selfty)
}; };
(ty::EarlyBinder::bind(impl_trait_ref), polarity_of_impl(tcx, def_id, impl_, item.span)) ty::EarlyBinder::bind(ty::ImplTraitHeader {
trait_ref,
polarity: polarity_of_impl(tcx, def_id, impl_, item.span)
})
}) })
} }

View File

@ -1973,7 +1973,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
if of_trait && let Some(header) = tcx.impl_trait_header(def_id) { if of_trait && let Some(header) = tcx.impl_trait_header(def_id) {
record!(self.tables.impl_trait_header[def_id] <- header); record!(self.tables.impl_trait_header[def_id] <- header);
let (trait_ref, _polarity) = header; let trait_ref = header.map_bound(|h| h.trait_ref);
let trait_ref = trait_ref.instantiate_identity(); let trait_ref = trait_ref.instantiate_identity();
let simplified_self_ty = fast_reject::simplify_type( let simplified_self_ty = fast_reject::simplify_type(

View File

@ -423,7 +423,7 @@ define_tables! {
variances_of: Table<DefIndex, LazyArray<ty::Variance>>, variances_of: Table<DefIndex, LazyArray<ty::Variance>>,
fn_sig: Table<DefIndex, LazyValue<ty::EarlyBinder<ty::PolyFnSig<'static>>>>, fn_sig: Table<DefIndex, LazyValue<ty::EarlyBinder<ty::PolyFnSig<'static>>>>,
codegen_fn_attrs: Table<DefIndex, LazyValue<CodegenFnAttrs>>, codegen_fn_attrs: Table<DefIndex, LazyValue<CodegenFnAttrs>>,
impl_trait_header: Table<DefIndex, LazyValue<(ty::EarlyBinder<ty::TraitRef<'static>>, ty::ImplPolarity)>>, impl_trait_header: Table<DefIndex, LazyValue<ty::EarlyBinder<ty::ImplTraitHeader<'static>>>>,
const_param_default: Table<DefIndex, LazyValue<ty::EarlyBinder<rustc_middle::ty::Const<'static>>>>, const_param_default: Table<DefIndex, LazyValue<ty::EarlyBinder<rustc_middle::ty::Const<'static>>>>,
object_lifetime_default: Table<DefIndex, LazyValue<ObjectLifetimeDefault>>, object_lifetime_default: Table<DefIndex, LazyValue<ObjectLifetimeDefault>>,
optimized_mir: Table<DefIndex, LazyValue<mir::Body<'static>>>, optimized_mir: Table<DefIndex, LazyValue<mir::Body<'static>>>,

View File

@ -177,9 +177,8 @@ impl EraseType for Option<mir::DestructuredConstant<'_>> {
type Result = [u8; size_of::<Option<mir::DestructuredConstant<'static>>>()]; type Result = [u8; size_of::<Option<mir::DestructuredConstant<'static>>>()];
} }
impl EraseType for Option<(ty::EarlyBinder<ty::TraitRef<'_>>, ty::ImplPolarity)> { impl EraseType for Option<ty::EarlyBinder<ty::ImplTraitHeader<'_>>> {
type Result = type Result = [u8; size_of::<Option<ty::EarlyBinder<ty::ImplTraitHeader<'static>>>>()];
[u8; size_of::<Option<(ty::EarlyBinder<ty::TraitRef<'static>>, ty::ImplPolarity)>>()];
} }
impl EraseType for Option<ty::EarlyBinder<Ty<'_>>> { impl EraseType for Option<ty::EarlyBinder<Ty<'_>>> {

View File

@ -848,7 +848,7 @@ rustc_queries! {
/// Given an `impl_id`, return the trait it implements along with some header information. /// Given an `impl_id`, return the trait it implements along with some header information.
/// Return `None` if this is an inherent impl. /// Return `None` if this is an inherent impl.
query impl_trait_header(impl_id: DefId) -> Option<(ty::EarlyBinder<ty::TraitRef<'tcx>>, ty::ImplPolarity)> { query impl_trait_header(impl_id: DefId) -> Option<ty::EarlyBinder<ty::ImplTraitHeader<'tcx>>> {
desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) } desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
cache_on_disk_if { impl_id.is_local() } cache_on_disk_if { impl_id.is_local() }
separate_provide_extern separate_provide_extern

View File

@ -2315,7 +2315,7 @@ impl<'tcx> TyCtxt<'tcx> {
self, self,
def_id: impl IntoQueryParam<DefId>, def_id: impl IntoQueryParam<DefId>,
) -> Option<ty::EarlyBinder<ty::TraitRef<'tcx>>> { ) -> Option<ty::EarlyBinder<ty::TraitRef<'tcx>>> {
Some(self.impl_trait_header(def_id)?.0) Some(self.impl_trait_header(def_id)?.map_bound(|h| h.trait_ref))
} }
} }

View File

@ -248,6 +248,12 @@ pub struct ImplHeader<'tcx> {
pub predicates: Vec<Predicate<'tcx>>, pub predicates: Vec<Predicate<'tcx>>,
} }
#[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable, TyEncodable, TyDecodable, HashStable)]
pub struct ImplTraitHeader<'tcx> {
pub trait_ref: ty::TraitRef<'tcx>,
pub polarity: ImplPolarity,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug, TypeFoldable, TypeVisitable)] #[derive(Copy, Clone, PartialEq, Eq, Debug, TypeFoldable, TypeVisitable)]
pub enum ImplSubject<'tcx> { pub enum ImplSubject<'tcx> {
Trait(TraitRef<'tcx>), Trait(TraitRef<'tcx>),

View File

@ -134,4 +134,5 @@ parameterized_over_tcx! {
ty::Predicate, ty::Predicate,
ty::Clause, ty::Clause,
ty::ClauseKind, ty::ClauseKind,
ty::ImplTraitHeader
} }