1
Fork 0

Rollup merge of #114079 - compiler-errors:closure-upvars, r=oli-obk

Use `upvar_tys` in more places, make it return a list

Just a cleanup that fell out of a PR that I was gonna write, but that PR kinda got stuck.
This commit is contained in:
Nilstrieb 2023-08-02 13:46:54 +02:00 committed by GitHub
commit 46f6b05eb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 66 additions and 78 deletions

View file

@ -317,7 +317,9 @@ fn layout_of_uncached<'tcx>(
ty::Closure(_, ref args) => {
let tys = args.as_closure().upvar_tys();
univariant(
&tys.map(|ty| Ok(cx.layout_of(ty)?.layout)).try_collect::<IndexVec<_, _>>()?,
&tys.iter()
.map(|ty| Ok(cx.layout_of(ty)?.layout))
.try_collect::<IndexVec<_, _>>()?,
&ReprOptions::default(),
StructKind::AlwaysSized,
)?
@ -729,7 +731,7 @@ fn generator_layout<'tcx>(
// Build a prefix layout, including "promoting" all ineligible
// locals as part of the prefix. We compute the layout of all of
// these fields at once to get optimal packing.
let tag_index = args.as_generator().prefix_tys().count();
let tag_index = args.as_generator().prefix_tys().len();
// `info.variant_fields` already accounts for the reserved variants, so no need to add them.
let max_discr = (info.variant_fields.len() - 1) as u128;
@ -748,6 +750,7 @@ fn generator_layout<'tcx>(
let prefix_layouts = args
.as_generator()
.prefix_tys()
.iter()
.map(|ty| Ok(cx.layout_of(ty)?.layout))
.chain(iter::once(Ok(tag_layout)))
.chain(promoted_layouts)
@ -1062,6 +1065,7 @@ fn variant_info_for_generator<'tcx>(
let upvar_fields: Vec<_> = args
.as_generator()
.upvar_tys()
.iter()
.zip(upvar_names)
.enumerate()
.map(|(field_idx, (_, name))| {

View file

@ -120,12 +120,16 @@ where
_ if component.is_copy_modulo_regions(tcx, self.param_env) => (),
ty::Closure(_, args) => {
queue_type(self, args.as_closure().tupled_upvars_ty());
for upvar in args.as_closure().upvar_tys() {
queue_type(self, upvar);
}
}
ty::Generator(def_id, args, _) => {
let args = args.as_generator();
queue_type(self, args.tupled_upvars_ty());
for upvar in args.upvar_tys() {
queue_type(self, upvar);
}
let witness = args.witness();
let interior_tys = match witness.kind() {