Skip to content

Commit 21906bd

Browse files
Add CoroutineClosure to TyKind, AggregateKind, UpvarArgs
1 parent c05f4b5 commit 21906bd

File tree

91 files changed

+579
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+579
-101
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1472,7 +1472,7 @@ fn suggest_ampmut<'tcx>(
14721472
}
14731473

14741474
fn is_closure_or_coroutine(ty: Ty<'_>) -> bool {
1475-
ty.is_closure() || ty.is_coroutine()
1475+
ty.is_closure() || ty.is_coroutine() || ty.is_coroutine_closure()
14761476
}
14771477

14781478
/// Given a field that needs to be mutable, returns a span where the " mut " could go.

compiler/rustc_borrowck/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13071307
// moved into the closure and subsequently used by the closure,
13081308
// in order to populate our used_mut set.
13091309
match **aggregate_kind {
1310-
AggregateKind::Closure(def_id, _) | AggregateKind::Coroutine(def_id, _) => {
1310+
AggregateKind::Closure(def_id, _)
1311+
| AggregateKind::CoroutineClosure(def_id, _)
1312+
| AggregateKind::Coroutine(def_id, _) => {
13111313
let def_id = def_id.expect_local();
13121314
let BorrowCheckResult { used_mut_upvars, .. } =
13131315
self.infcx.tcx.mir_borrowck(def_id);
@@ -1613,6 +1615,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16131615
| ty::FnPtr(_)
16141616
| ty::Dynamic(_, _, _)
16151617
| ty::Closure(_, _)
1618+
| ty::CoroutineClosure(_, _)
16161619
| ty::Coroutine(_, _)
16171620
| ty::CoroutineWitness(..)
16181621
| ty::Never
@@ -1637,7 +1640,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16371640
return;
16381641
}
16391642
}
1640-
ty::Closure(_, _) | ty::Coroutine(_, _) | ty::Tuple(_) => (),
1643+
ty::Closure(..)
1644+
| ty::CoroutineClosure(..)
1645+
| ty::Coroutine(_, _)
1646+
| ty::Tuple(_) => (),
16411647
ty::Bool
16421648
| ty::Char
16431649
| ty::Int(_)

compiler/rustc_borrowck/src/path_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ pub(crate) fn is_upvar_field_projection<'tcx>(
164164
match place_ref.last_projection() {
165165
Some((place_base, ProjectionElem::Field(field, _ty))) => {
166166
let base_ty = place_base.ty(body, tcx).ty;
167-
if (base_ty.is_closure() || base_ty.is_coroutine())
167+
if (base_ty.is_closure() || base_ty.is_coroutine() || base_ty.is_coroutine_closure())
168168
&& (!by_ref || upvars[field.index()].is_by_ref())
169169
{
170170
Some(field)

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,14 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
802802
}),
803803
};
804804
}
805+
ty::CoroutineClosure(_, args) => {
806+
return match args.as_coroutine_closure().upvar_tys().get(field.index()) {
807+
Some(&ty) => Ok(ty),
808+
None => Err(FieldAccessError::OutOfRange {
809+
field_count: args.as_coroutine_closure().upvar_tys().len(),
810+
}),
811+
};
812+
}
805813
ty::Coroutine(_, args) => {
806814
// Only prefix fields (upvars and current state) are
807815
// accessible without a variant index.
@@ -1829,6 +1837,14 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18291837
}),
18301838
}
18311839
}
1840+
AggregateKind::CoroutineClosure(_, args) => {
1841+
match args.as_coroutine_closure().upvar_tys().get(field_index.as_usize()) {
1842+
Some(ty) => Ok(*ty),
1843+
None => Err(FieldAccessError::OutOfRange {
1844+
field_count: args.as_coroutine_closure().upvar_tys().len(),
1845+
}),
1846+
}
1847+
}
18321848
AggregateKind::Array(ty) => Ok(ty),
18331849
AggregateKind::Tuple => {
18341850
unreachable!("This should have been covered in check_rvalues");
@@ -2427,6 +2443,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24272443
AggregateKind::Tuple => None,
24282444
AggregateKind::Closure(_, _) => None,
24292445
AggregateKind::Coroutine(_, _) => None,
2446+
AggregateKind::CoroutineClosure(_, _) => None,
24302447
},
24312448
}
24322449
}
@@ -2654,7 +2671,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
26542671
// desugaring. A closure gets desugared to a struct, and
26552672
// these extra requirements are basically like where
26562673
// clauses on the struct.
2657-
AggregateKind::Closure(def_id, args) | AggregateKind::Coroutine(def_id, args) => {
2674+
AggregateKind::Closure(def_id, args)
2675+
| AggregateKind::CoroutineClosure(def_id, args)
2676+
| AggregateKind::Coroutine(def_id, args) => {
26582677
(def_id, self.prove_closure_bounds(tcx, def_id.expect_local(), args, location))
26592678
}
26602679

@@ -2697,10 +2716,16 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
26972716
let typeck_root_args = ty::GenericArgs::identity_for_item(tcx, typeck_root_def_id);
26982717

26992718
let parent_args = match tcx.def_kind(def_id) {
2700-
DefKind::Closure if tcx.is_coroutine(def_id.to_def_id()) => {
2701-
args.as_coroutine().parent_args()
2719+
DefKind::Closure => {
2720+
// FIXME(async_closures): It's kind of icky to access HIR here.
2721+
match tcx.hir_node_by_def_id(def_id).expect_closure().kind {
2722+
hir::ClosureKind::Closure => args.as_closure().parent_args(),
2723+
hir::ClosureKind::Coroutine(_) => args.as_coroutine().parent_args(),
2724+
hir::ClosureKind::CoroutineClosure(_) => {
2725+
args.as_coroutine_closure().parent_args()
2726+
}
2727+
}
27022728
}
2703-
DefKind::Closure => args.as_closure().parent_args(),
27042729
DefKind::InlineConst => args.as_inline_const().parent_args(),
27052730
other => bug!("unexpected item {:?}", other),
27062731
};

compiler/rustc_codegen_gcc/src/type_of.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ fn uncached_gcc_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, layout: TyAndLayout
8787
// FIXME(eddyb) producing readable type names for trait objects can result
8888
// in problematically distinct types due to HRTB and subtyping (see #47638).
8989
// ty::Dynamic(..) |
90-
ty::Adt(..) | ty::Closure(..) | ty::Foreign(..) | ty::Coroutine(..) | ty::Str
90+
ty::Adt(..) | ty::Closure(..) | ty::CoroutineClosure(..) | ty::Foreign(..) | ty::Coroutine(..) | ty::Str
9191
if !cx.sess().fewer_names() =>
9292
{
9393
let mut name = with_no_trimmed_paths!(layout.ty.to_string());

compiler/rustc_codegen_llvm/src/type_of.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn uncached_llvm_type<'a, 'tcx>(
3333
// FIXME(eddyb) producing readable type names for trait objects can result
3434
// in problematically distinct types due to HRTB and subtyping (see #47638).
3535
// ty::Dynamic(..) |
36-
ty::Adt(..) | ty::Closure(..) | ty::Foreign(..) | ty::Coroutine(..) | ty::Str
36+
ty::Adt(..) | ty::Closure(..) | ty::CoroutineClosure(..) | ty::Foreign(..) | ty::Coroutine(..) | ty::Str
3737
// For performance reasons we use names only when emitting LLVM IR.
3838
if !cx.sess().fewer_names() =>
3939
{

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,9 @@ fn push_debuginfo_type_name<'tcx>(
398398
// processing
399399
visited.remove(&t);
400400
}
401-
ty::Closure(def_id, args) | ty::Coroutine(def_id, args, ..) => {
401+
ty::Closure(def_id, args)
402+
| ty::CoroutineClosure(def_id, args)
403+
| ty::Coroutine(def_id, args, ..) => {
402404
// Name will be "{closure_env#0}<T1, T2, ...>", "{coroutine_env#0}<T1, T2, ...>", or
403405
// "{async_fn_env#0}<T1, T2, ...>", etc.
404406
// In the case of cpp-like debuginfo, the name additionally gets wrapped inside of
@@ -768,6 +770,8 @@ fn push_closure_or_coroutine_name<'tcx>(
768770

769771
// Truncate the args to the length of the above generics. This will cut off
770772
// anything closure- or coroutine-specific.
773+
// FIXME(async_closures): This is probably not going to be correct w.r.t.
774+
// multiple coroutine flavors. Maybe truncate to (parent + 1)?
771775
let args = args.truncate_to(tcx, generics);
772776
push_generic_params_internal(tcx, args, enclosing_fn_def_id, output, visited);
773777
}

compiler/rustc_const_eval/src/const_eval/valtrees.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ pub(crate) fn const_to_valtree_inner<'tcx>(
172172
| ty::Infer(_)
173173
// FIXME(oli-obk): we can probably encode closures just like structs
174174
| ty::Closure(..)
175+
| ty::CoroutineClosure(..)
175176
| ty::Coroutine(..)
176177
| ty::CoroutineWitness(..) => Err(ValTreeCreationError::NonSupportedType),
177178
}
@@ -301,6 +302,7 @@ pub fn valtree_to_const_value<'tcx>(
301302
| ty::Placeholder(..)
302303
| ty::Infer(_)
303304
| ty::Closure(..)
305+
| ty::CoroutineClosure(..)
304306
| ty::Coroutine(..)
305307
| ty::CoroutineWitness(..)
306308
| ty::FnPtr(_)

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
10071007
| ty::CoroutineWitness(..)
10081008
| ty::Array(..)
10091009
| ty::Closure(..)
1010+
| ty::CoroutineClosure(..)
10101011
| ty::Never
10111012
| ty::Error(_) => true,
10121013

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>(
8585
| ty::FnPtr(_)
8686
| ty::Dynamic(_, _, _)
8787
| ty::Closure(_, _)
88+
| ty::CoroutineClosure(_, _)
8889
| ty::Coroutine(_, _)
8990
| ty::CoroutineWitness(..)
9091
| ty::Never

0 commit comments

Comments
 (0)