Skip to content

Commit 67345f9

Browse files
author
Lukas Markeffsky
committed
remove useless parameter
Remove the `repr` parameter from the wrappers around `calc.univariant`, because it's always defaulted. Only ADTs can have a repr and those call `calc.layout_of_struct_or_enum` and not `calc.univariant`.
1 parent 1d1ac3d commit 67345f9

File tree

1 file changed

+10
-36
lines changed

1 file changed

+10
-36
lines changed

compiler/rustc_ty_utils/src/layout.rs

+10-36
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,10 @@ fn univariant_uninterned<'tcx>(
134134
cx: &LayoutCx<'tcx>,
135135
ty: Ty<'tcx>,
136136
fields: &IndexSlice<FieldIdx, TyAndLayout<'tcx>>,
137-
repr: &ReprOptions,
138137
kind: StructKind,
139138
) -> Result<LayoutData<FieldIdx, VariantIdx>, &'tcx LayoutError<'tcx>> {
140-
let pack = repr.pack;
141-
if pack.is_some() && repr.align.is_some() {
142-
cx.tcx().dcx().bug("struct cannot be packed and aligned");
143-
}
144-
145-
cx.calc.univariant(fields, repr, kind).map_err(|err| map_error(cx, ty, err))
139+
let repr = ReprOptions::default();
140+
cx.calc.univariant(fields, &repr, kind).map_err(|err| map_error(cx, ty, err))
146141
}
147142

148143
fn extract_const_value<'tcx>(
@@ -189,10 +184,9 @@ fn layout_of_uncached<'tcx>(
189184
};
190185
let scalar = |value: Primitive| tcx.mk_layout(LayoutData::scalar(cx, scalar_unit(value)));
191186

192-
let univariant =
193-
|fields: &IndexSlice<FieldIdx, TyAndLayout<'tcx>>, repr: &ReprOptions, kind| {
194-
Ok(tcx.mk_layout(univariant_uninterned(cx, ty, fields, repr, kind)?))
195-
};
187+
let univariant = |fields: &IndexSlice<FieldIdx, TyAndLayout<'tcx>>, kind| {
188+
Ok(tcx.mk_layout(univariant_uninterned(cx, ty, fields, kind)?))
189+
};
196190
debug_assert!(!ty.has_non_region_infer());
197191

198192
Ok(match *ty.kind() {
@@ -405,17 +399,10 @@ fn layout_of_uncached<'tcx>(
405399
}),
406400

407401
// Odd unit types.
408-
ty::FnDef(..) => {
409-
univariant(IndexSlice::empty(), &ReprOptions::default(), StructKind::AlwaysSized)?
410-
}
402+
ty::FnDef(..) => univariant(IndexSlice::empty(), StructKind::AlwaysSized)?,
411403
ty::Dynamic(_, _, ty::Dyn) | ty::Foreign(..) => {
412-
let mut unit = univariant_uninterned(
413-
cx,
414-
ty,
415-
IndexSlice::empty(),
416-
&ReprOptions::default(),
417-
StructKind::AlwaysSized,
418-
)?;
404+
let mut unit =
405+
univariant_uninterned(cx, ty, IndexSlice::empty(), StructKind::AlwaysSized)?;
419406
match unit.backend_repr {
420407
BackendRepr::Memory { ref mut sized } => *sized = false,
421408
_ => bug!(),
@@ -429,7 +416,6 @@ fn layout_of_uncached<'tcx>(
429416
let tys = args.as_closure().upvar_tys();
430417
univariant(
431418
&tys.iter().map(|ty| cx.layout_of(ty)).try_collect::<IndexVec<_, _>>()?,
432-
&ReprOptions::default(),
433419
StructKind::AlwaysSized,
434420
)?
435421
}
@@ -438,7 +424,6 @@ fn layout_of_uncached<'tcx>(
438424
let tys = args.as_coroutine_closure().upvar_tys();
439425
univariant(
440426
&tys.iter().map(|ty| cx.layout_of(ty)).try_collect::<IndexVec<_, _>>()?,
441-
&ReprOptions::default(),
442427
StructKind::AlwaysSized,
443428
)?
444429
}
@@ -447,11 +432,7 @@ fn layout_of_uncached<'tcx>(
447432
let kind =
448433
if tys.len() == 0 { StructKind::AlwaysSized } else { StructKind::MaybeUnsized };
449434

450-
univariant(
451-
&tys.iter().map(|k| cx.layout_of(k)).try_collect::<IndexVec<_, _>>()?,
452-
&ReprOptions::default(),
453-
kind,
454-
)?
435+
univariant(&tys.iter().map(|k| cx.layout_of(k)).try_collect::<IndexVec<_, _>>()?, kind)?
455436
}
456437

457438
// SIMD vector types.
@@ -902,13 +883,7 @@ fn coroutine_layout<'tcx>(
902883
.chain(iter::once(Ok(tag_layout)))
903884
.chain(promoted_layouts)
904885
.try_collect::<IndexVec<_, _>>()?;
905-
let prefix = univariant_uninterned(
906-
cx,
907-
ty,
908-
&prefix_layouts,
909-
&ReprOptions::default(),
910-
StructKind::AlwaysSized,
911-
)?;
886+
let prefix = univariant_uninterned(cx, ty, &prefix_layouts, StructKind::AlwaysSized)?;
912887

913888
let (prefix_size, prefix_align) = (prefix.size, prefix.align);
914889

@@ -973,7 +948,6 @@ fn coroutine_layout<'tcx>(
973948
cx,
974949
ty,
975950
&variant_only_tys.map(|ty| cx.layout_of(ty)).try_collect::<IndexVec<_, _>>()?,
976-
&ReprOptions::default(),
977951
StructKind::Prefixed(prefix_size, prefix_align.abi),
978952
)?;
979953
variant.variants = Variants::Single { index };

0 commit comments

Comments
 (0)