1
Fork 0

Implement Deref<LayoutS> for Layout

This commit is contained in:
Lukas Wirth 2023-09-29 18:00:06 +02:00
parent 67e5eb6cec
commit 6d141c11c0
4 changed files with 11 additions and 4 deletions

View file

@ -8,7 +8,7 @@
macro_rules! arena_types { macro_rules! arena_types {
($macro:path) => ( ($macro:path) => (
$macro!([ $macro!([
[] layout: rustc_target::abi::LayoutS, [] layout: rustc_target::abi::LayoutS<rustc_target::abi::FieldIdx, rustc_target::abi::VariantIdx>,
[] fn_abi: rustc_target::abi::call::FnAbi<'tcx, rustc_middle::ty::Ty<'tcx>>, [] fn_abi: rustc_target::abi::call::FnAbi<'tcx, rustc_middle::ty::Ty<'tcx>>,
// AdtDef are interned and compared by address // AdtDef are interned and compared by address
[decode] adt_def: rustc_middle::ty::AdtDefData, [decode] adt_def: rustc_middle::ty::AdtDefData,

View file

@ -152,7 +152,7 @@ pub struct CtxtInterners<'tcx> {
const_: InternedSet<'tcx, ConstData<'tcx>>, const_: InternedSet<'tcx, ConstData<'tcx>>,
const_allocation: InternedSet<'tcx, Allocation>, const_allocation: InternedSet<'tcx, Allocation>,
bound_variable_kinds: InternedSet<'tcx, List<ty::BoundVariableKind>>, bound_variable_kinds: InternedSet<'tcx, List<ty::BoundVariableKind>>,
layout: InternedSet<'tcx, LayoutS>, layout: InternedSet<'tcx, LayoutS<FieldIdx, VariantIdx>>,
adt_def: InternedSet<'tcx, AdtDefData>, adt_def: InternedSet<'tcx, AdtDefData>,
external_constraints: InternedSet<'tcx, ExternalConstraintsData<'tcx>>, external_constraints: InternedSet<'tcx, ExternalConstraintsData<'tcx>>,
predefined_opaques_in_body: InternedSet<'tcx, PredefinedOpaquesData<'tcx>>, predefined_opaques_in_body: InternedSet<'tcx, PredefinedOpaquesData<'tcx>>,
@ -1521,7 +1521,7 @@ direct_interners! {
region: pub(crate) intern_region(RegionKind<'tcx>): Region -> Region<'tcx>, region: pub(crate) intern_region(RegionKind<'tcx>): Region -> Region<'tcx>,
const_: intern_const(ConstData<'tcx>): Const -> Const<'tcx>, const_: intern_const(ConstData<'tcx>): Const -> Const<'tcx>,
const_allocation: pub mk_const_alloc(Allocation): ConstAllocation -> ConstAllocation<'tcx>, const_allocation: pub mk_const_alloc(Allocation): ConstAllocation -> ConstAllocation<'tcx>,
layout: pub mk_layout(LayoutS): Layout -> Layout<'tcx>, layout: pub mk_layout(LayoutS<FieldIdx, VariantIdx>): Layout -> Layout<'tcx>,
adt_def: pub mk_adt_def_from_data(AdtDefData): AdtDef -> AdtDef<'tcx>, adt_def: pub mk_adt_def_from_data(AdtDefData): AdtDef -> AdtDef<'tcx>,
external_constraints: pub mk_external_constraints(ExternalConstraintsData<'tcx>): external_constraints: pub mk_external_constraints(ExternalConstraintsData<'tcx>):
ExternalConstraints -> ExternalConstraints<'tcx>, ExternalConstraints -> ExternalConstraints<'tcx>,

View file

@ -73,6 +73,13 @@ impl<'a> fmt::Debug for Layout<'a> {
} }
} }
impl<'a> Deref for Layout<'a> {
type Target = &'a LayoutS<FieldIdx, VariantIdx>;
fn deref(&self) -> &&'a LayoutS<FieldIdx, VariantIdx> {
&self.0.0
}
}
impl<'a> Layout<'a> { impl<'a> Layout<'a> {
pub fn fields(self) -> &'a FieldsShape<FieldIdx> { pub fn fields(self) -> &'a FieldsShape<FieldIdx> {
&self.0.0.fields &self.0.0.fields

View file

@ -85,7 +85,7 @@ fn univariant_uninterned<'tcx>(
fields: &IndexSlice<FieldIdx, Layout<'_>>, fields: &IndexSlice<FieldIdx, Layout<'_>>,
repr: &ReprOptions, repr: &ReprOptions,
kind: StructKind, kind: StructKind,
) -> Result<LayoutS, &'tcx LayoutError<'tcx>> { ) -> Result<LayoutS<FieldIdx, VariantIdx>, &'tcx LayoutError<'tcx>> {
let dl = cx.data_layout(); let dl = cx.data_layout();
let pack = repr.pack; let pack = repr.pack;
if pack.is_some() && repr.align.is_some() { if pack.is_some() && repr.align.is_some() {