Skip to content

Commit c567edd

Browse files
Add CoroutineClosure to TyKind, AggregateKind, UpvarArgs
1 parent a204217 commit c567edd

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
@@ -1303,7 +1303,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13031303
// moved into the closure and subsequently used by the closure,
13041304
// in order to populate our used_mut set.
13051305
match **aggregate_kind {
1306-
AggregateKind::Closure(def_id, _) | AggregateKind::Coroutine(def_id, _) => {
1306+
AggregateKind::Closure(def_id, _)
1307+
| AggregateKind::CoroutineClosure(def_id, _)
1308+
| AggregateKind::Coroutine(def_id, _) => {
13071309
let def_id = def_id.expect_local();
13081310
let BorrowCheckResult { used_mut_upvars, .. } =
13091311
self.infcx.tcx.mir_borrowck(def_id);
@@ -1609,6 +1611,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16091611
| ty::FnPtr(_)
16101612
| ty::Dynamic(_, _, _)
16111613
| ty::Closure(_, _)
1614+
| ty::CoroutineClosure(_, _)
16121615
| ty::Coroutine(_, _)
16131616
| ty::CoroutineWitness(..)
16141617
| ty::Never
@@ -1633,7 +1636,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16331636
return;
16341637
}
16351638
}
1636-
ty::Closure(_, _) | ty::Coroutine(_, _) | ty::Tuple(_) => (),
1639+
ty::Closure(..)
1640+
| ty::CoroutineClosure(..)
1641+
| ty::Coroutine(_, _)
1642+
| ty::Tuple(_) => (),
16371643
ty::Bool
16381644
| ty::Char
16391645
| 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
@@ -808,6 +808,14 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
808808
}),
809809
};
810810
}
811+
ty::CoroutineClosure(_, args) => {
812+
return match args.as_coroutine_closure().upvar_tys().get(field.index()) {
813+
Some(&ty) => Ok(ty),
814+
None => Err(FieldAccessError::OutOfRange {
815+
field_count: args.as_coroutine_closure().upvar_tys().len(),
816+
}),
817+
};
818+
}
811819
ty::Coroutine(_, args) => {
812820
// Only prefix fields (upvars and current state) are
813821
// accessible without a variant index.
@@ -1875,6 +1883,14 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18751883
}),
18761884
}
18771885
}
1886+
AggregateKind::CoroutineClosure(_, args) => {
1887+
match args.as_coroutine_closure().upvar_tys().get(field_index.as_usize()) {
1888+
Some(ty) => Ok(*ty),
1889+
None => Err(FieldAccessError::OutOfRange {
1890+
field_count: args.as_coroutine_closure().upvar_tys().len(),
1891+
}),
1892+
}
1893+
}
18781894
AggregateKind::Array(ty) => Ok(ty),
18791895
AggregateKind::Tuple => {
18801896
unreachable!("This should have been covered in check_rvalues");
@@ -2478,6 +2494,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24782494
AggregateKind::Tuple => None,
24792495
AggregateKind::Closure(_, _) => None,
24802496
AggregateKind::Coroutine(_, _) => None,
2497+
AggregateKind::CoroutineClosure(_, _) => None,
24812498
},
24822499
}
24832500
}
@@ -2705,7 +2722,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
27052722
// desugaring. A closure gets desugared to a struct, and
27062723
// these extra requirements are basically like where
27072724
// clauses on the struct.
2708-
AggregateKind::Closure(def_id, args) | AggregateKind::Coroutine(def_id, args) => (
2725+
AggregateKind::Closure(def_id, args)
2726+
| AggregateKind::CoroutineClosure(def_id, args)
2727+
| AggregateKind::Coroutine(def_id, args) => (
27092728
def_id,
27102729
self.prove_closure_bounds(
27112730
tcx,
@@ -2754,10 +2773,16 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
27542773
let typeck_root_args = ty::GenericArgs::identity_for_item(tcx, typeck_root_def_id);
27552774

27562775
let parent_args = match tcx.def_kind(def_id) {
2757-
DefKind::Closure if tcx.is_coroutine(def_id.to_def_id()) => {
2758-
args.as_coroutine().parent_args()
2776+
DefKind::Closure => {
2777+
// FIXME(async_closures): It's kind of icky to access HIR here.
2778+
match tcx.hir_node_by_def_id(def_id).expect_closure().kind {
2779+
hir::ClosureKind::Closure => args.as_closure().parent_args(),
2780+
hir::ClosureKind::Coroutine(_) => args.as_coroutine().parent_args(),
2781+
hir::ClosureKind::CoroutineClosure(_) => {
2782+
args.as_coroutine_closure().parent_args()
2783+
}
2784+
}
27592785
}
2760-
DefKind::Closure => args.as_closure().parent_args(),
27612786
DefKind::InlineConst => args.as_inline_const().parent_args(),
27622787
other => bug!("unexpected item {:?}", other),
27632788
};

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)