Skip to content

Commit c627c0d

Browse files
committed
Fix nits.
1 parent 89a369a commit c627c0d

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

compiler/rustc_codegen_llvm/src/type_of.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ fn struct_llfields<'a, 'tcx>(
101101
let mut offset = Size::ZERO;
102102
let mut prev_effective_align = layout.align.abi;
103103
let mut result: Vec<_> = Vec::with_capacity(1 + field_count * 2);
104-
let mut projection = vec![0; field_count];
105-
let mut padding_used = false;
104+
let mut field_remapping = vec![0; field_count];
106105
for i in layout.fields.index_by_increasing_offset() {
107106
let target_offset = layout.fields.offset(i as usize);
108107
let field = layout.field(cx, i);
@@ -122,17 +121,17 @@ fn struct_llfields<'a, 'tcx>(
122121
assert!(target_offset >= offset);
123122
let padding = target_offset - offset;
124123
if padding != Size::ZERO {
125-
padding_used = true;
126124
let padding_align = prev_effective_align.min(effective_field_align);
127125
assert_eq!(offset.align_to(padding_align) + padding, target_offset);
128126
result.push(cx.type_padding_filler(padding, padding_align));
129127
debug!(" padding before: {:?}", padding);
130128
}
131-
projection[i] = result.len() as u32;
129+
field_remapping[i] = result.len() as u32;
132130
result.push(field.llvm_type(cx));
133131
offset = target_offset + field.size;
134132
prev_effective_align = effective_field_align;
135133
}
134+
let padding_used = result.len() > field_count;
136135
if !layout.is_unsized() && field_count > 0 {
137136
if offset > layout.size {
138137
bug!("layout: {:#?} stride: {:?} offset: {:?}", layout, layout.size, offset);
@@ -151,7 +150,7 @@ fn struct_llfields<'a, 'tcx>(
151150
debug!("struct_llfields: offset: {:?} stride: {:?}", offset, layout.size);
152151
}
153152

154-
(result, packed, padding_used.then_some(projection.into_boxed_slice()))
153+
(result, packed, padding_used.then_some(field_remapping.into_boxed_slice()))
155154
}
156155

157156
impl<'a, 'tcx> CodegenCx<'a, 'tcx> {
@@ -268,17 +267,20 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
268267
};
269268
debug!("--> mapped {:#?} to llty={:?}", self, llty);
270269

271-
cx.type_lowering
272-
.borrow_mut()
273-
.insert((self.ty, variant_index), TypeLowering { lltype: llty, field_remapping: None });
270+
cx.type_lowering.borrow_mut().insert(
271+
(self.ty, variant_index),
272+
TypeLowering { lltype: llty, field_remapping: field_remapping },
273+
);
274274

275275
if let Some((llty, layout)) = defer {
276276
let (llfields, packed, new_field_remapping) = struct_llfields(cx, layout);
277277
cx.set_struct_body(llty, &llfields, packed);
278-
field_remapping = new_field_remapping;
278+
cx.type_lowering
279+
.borrow_mut()
280+
.get_mut(&(self.ty, variant_index))
281+
.unwrap()
282+
.field_remapping = new_field_remapping;
279283
}
280-
cx.type_lowering.borrow_mut().get_mut(&(self.ty, variant_index)).unwrap().field_remapping =
281-
field_remapping;
282284
llty
283285
}
284286

@@ -378,7 +380,9 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
378380
// `field_remapping` is `None` no padding was used and the llvm field index
379381
// matches the memory index.
380382
match cx.type_lowering.borrow().get(&(self.ty, variant_index)) {
381-
Some(TypeLowering { field_remapping: Some(ref prj), .. }) => prj[index] as u64,
383+
Some(TypeLowering { field_remapping: Some(ref remap), .. }) => {
384+
remap[index] as u64
385+
}
382386
Some(_) => self.fields.memory_index(index) as u64,
383387
None => {
384388
bug!("TyAndLayout::llvm_field_index({:?}): type info not found", self)

0 commit comments

Comments
 (0)