1
Fork 0

Remove movability from TyKind::Coroutine

This commit is contained in:
Michael Goulet 2023-12-21 01:52:10 +00:00
parent f4d794ea0b
commit fcb42b42d6
84 changed files with 212 additions and 220 deletions

View file

@ -370,7 +370,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
ty::Array(ty, _) | ty::Slice(ty) => { ty::Array(ty, _) | ty::Slice(ty) => {
self.describe_field_from_ty(ty, field, variant_index, including_tuple_field) self.describe_field_from_ty(ty, field, variant_index, including_tuple_field)
} }
ty::Closure(def_id, _) | ty::Coroutine(def_id, _, _) => { ty::Closure(def_id, _) | ty::Coroutine(def_id, _) => {
// We won't be borrowck'ing here if the closure came from another crate, // We won't be borrowck'ing here if the closure came from another crate,
// so it's safe to call `expect_local`. // so it's safe to call `expect_local`.
// //
@ -792,8 +792,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
debug!("move_spans: moved_place={:?} location={:?} stmt={:?}", moved_place, location, stmt); debug!("move_spans: moved_place={:?} location={:?} stmt={:?}", moved_place, location, stmt);
if let StatementKind::Assign(box (_, Rvalue::Aggregate(kind, places))) = &stmt.kind if let StatementKind::Assign(box (_, Rvalue::Aggregate(kind, places))) = &stmt.kind
&& let AggregateKind::Closure(def_id, _) | AggregateKind::Coroutine(def_id, _, _) = && let AggregateKind::Closure(def_id, _) | AggregateKind::Coroutine(def_id, _) = **kind
**kind
{ {
debug!("move_spans: def_id={:?} places={:?}", def_id, places); debug!("move_spans: def_id={:?} places={:?}", def_id, places);
let def_id = def_id.expect_local(); let def_id = def_id.expect_local();
@ -928,7 +927,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
if let StatementKind::Assign(box (_, Rvalue::Aggregate(kind, places))) = &stmt.kind { if let StatementKind::Assign(box (_, Rvalue::Aggregate(kind, places))) = &stmt.kind {
let (&def_id, is_coroutine) = match kind { let (&def_id, is_coroutine) = match kind {
box AggregateKind::Closure(def_id, _) => (def_id, false), box AggregateKind::Closure(def_id, _) => (def_id, false),
box AggregateKind::Coroutine(def_id, _, _) => (def_id, true), box AggregateKind::Coroutine(def_id, _) => (def_id, true),
_ => continue, _ => continue,
}; };
let def_id = def_id.expect_local(); let def_id = def_id.expect_local();

View file

@ -274,11 +274,12 @@ fn do_mir_borrowck<'tcx>(
// The first argument is the coroutine type passed by value // The first argument is the coroutine type passed by value
if let Some(local) = body.local_decls.raw.get(1) if let Some(local) = body.local_decls.raw.get(1)
// Get the interior types and args which typeck computed // Get the interior types and args which typeck computed
&& let ty::Coroutine(_, _, hir::Movability::Static) = local.ty.kind() && let ty::Coroutine(def_id, _) = *local.ty.kind()
&& tcx.movability(def_id) == hir::Movability::Movable
{ {
false
} else {
true true
} else {
false
}; };
for (idx, move_data) in promoted_move_data { for (idx, move_data) in promoted_move_data {
@ -1306,7 +1307,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
// moved into the closure and subsequently used by the closure, // moved into the closure and subsequently used by the closure,
// in order to populate our used_mut set. // in order to populate our used_mut set.
match **aggregate_kind { match **aggregate_kind {
AggregateKind::Closure(def_id, _) | AggregateKind::Coroutine(def_id, _, _) => { AggregateKind::Closure(def_id, _) | AggregateKind::Coroutine(def_id, _) => {
let def_id = def_id.expect_local(); let def_id = def_id.expect_local();
let BorrowCheckResult { used_mut_upvars, .. } = let BorrowCheckResult { used_mut_upvars, .. } =
self.infcx.tcx.mir_borrowck(def_id); self.infcx.tcx.mir_borrowck(def_id);
@ -1612,7 +1613,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
| ty::FnPtr(_) | ty::FnPtr(_)
| ty::Dynamic(_, _, _) | ty::Dynamic(_, _, _)
| ty::Closure(_, _) | ty::Closure(_, _)
| ty::Coroutine(_, _, _) | ty::Coroutine(_, _)
| ty::CoroutineWitness(..) | ty::CoroutineWitness(..)
| ty::Never | ty::Never
| ty::Tuple(_) | ty::Tuple(_)
@ -1636,7 +1637,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
return; return;
} }
} }
ty::Closure(_, _) | ty::Coroutine(_, _, _) | ty::Tuple(_) => (), ty::Closure(_, _) | ty::Coroutine(_, _) | ty::Tuple(_) => (),
ty::Bool ty::Bool
| ty::Char | ty::Char
| ty::Int(_) | ty::Int(_)

View file

@ -762,7 +762,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
let (variant, args) = match base_ty { let (variant, args) = match base_ty {
PlaceTy { ty, variant_index: Some(variant_index) } => match *ty.kind() { PlaceTy { ty, variant_index: Some(variant_index) } => match *ty.kind() {
ty::Adt(adt_def, args) => (adt_def.variant(variant_index), args), ty::Adt(adt_def, args) => (adt_def.variant(variant_index), args),
ty::Coroutine(def_id, args, _) => { ty::Coroutine(def_id, args) => {
let mut variants = args.as_coroutine().state_tys(def_id, tcx); let mut variants = args.as_coroutine().state_tys(def_id, tcx);
let Some(mut variant) = variants.nth(variant_index.into()) else { let Some(mut variant) = variants.nth(variant_index.into()) else {
bug!( bug!(
@ -790,7 +790,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
}), }),
}; };
} }
ty::Coroutine(_, args, _) => { ty::Coroutine(_, args) => {
// Only prefix fields (upvars and current state) are // Only prefix fields (upvars and current state) are
// accessible without a variant index. // accessible without a variant index.
return match args.as_coroutine().prefix_tys().get(field.index()) { return match args.as_coroutine().prefix_tys().get(field.index()) {
@ -1784,7 +1784,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
}), }),
} }
} }
AggregateKind::Coroutine(_, args, _) => { AggregateKind::Coroutine(_, args) => {
// It doesn't make sense to look at a field beyond the prefix; // It doesn't make sense to look at a field beyond the prefix;
// these require a variant index, and are not initialized in // these require a variant index, and are not initialized in
// aggregate rvalues. // aggregate rvalues.
@ -2392,7 +2392,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
AggregateKind::Array(_) => None, AggregateKind::Array(_) => None,
AggregateKind::Tuple => None, AggregateKind::Tuple => None,
AggregateKind::Closure(_, _) => None, AggregateKind::Closure(_, _) => None,
AggregateKind::Coroutine(_, _, _) => None, AggregateKind::Coroutine(_, _) => None,
}, },
} }
} }
@ -2620,7 +2620,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
// desugaring. A closure gets desugared to a struct, and // desugaring. A closure gets desugared to a struct, and
// these extra requirements are basically like where // these extra requirements are basically like where
// clauses on the struct. // clauses on the struct.
AggregateKind::Closure(def_id, args) | AggregateKind::Coroutine(def_id, args, _) => { AggregateKind::Closure(def_id, args) | AggregateKind::Coroutine(def_id, args) => {
(def_id, self.prove_closure_bounds(tcx, def_id.expect_local(), args, location)) (def_id, self.prove_closure_bounds(tcx, def_id.expect_local(), args, location))
} }

View file

@ -14,7 +14,6 @@
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_errors::Diagnostic; use rustc_errors::Diagnostic;
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;
use rustc_hir::BodyOwnerKind; use rustc_hir::BodyOwnerKind;
@ -94,7 +93,7 @@ pub enum DefiningTy<'tcx> {
/// The MIR is a coroutine. The signature is that coroutines take /// The MIR is a coroutine. The signature is that coroutines take
/// no parameters and return the result of /// no parameters and return the result of
/// `ClosureArgs::coroutine_return_ty`. /// `ClosureArgs::coroutine_return_ty`.
Coroutine(DefId, GenericArgsRef<'tcx>, hir::Movability), Coroutine(DefId, GenericArgsRef<'tcx>),
/// The MIR is a fn item with the given `DefId` and args. The signature /// The MIR is a fn item with the given `DefId` and args. The signature
/// of the function can be bound then with the `fn_sig` query. /// of the function can be bound then with the `fn_sig` query.
@ -118,7 +117,7 @@ impl<'tcx> DefiningTy<'tcx> {
pub fn upvar_tys(self) -> &'tcx ty::List<Ty<'tcx>> { pub fn upvar_tys(self) -> &'tcx ty::List<Ty<'tcx>> {
match self { match self {
DefiningTy::Closure(_, args) => args.as_closure().upvar_tys(), DefiningTy::Closure(_, args) => args.as_closure().upvar_tys(),
DefiningTy::Coroutine(_, args, _) => args.as_coroutine().upvar_tys(), DefiningTy::Coroutine(_, args) => args.as_coroutine().upvar_tys(),
DefiningTy::FnDef(..) | DefiningTy::Const(..) | DefiningTy::InlineConst(..) => { DefiningTy::FnDef(..) | DefiningTy::Const(..) | DefiningTy::InlineConst(..) => {
ty::List::empty() ty::List::empty()
} }
@ -354,7 +353,7 @@ impl<'tcx> UniversalRegions<'tcx> {
err.note(format!("late-bound region is {:?}", self.to_region_vid(r))); err.note(format!("late-bound region is {:?}", self.to_region_vid(r)));
}); });
} }
DefiningTy::Coroutine(def_id, args, _) => { DefiningTy::Coroutine(def_id, args) => {
let v = with_no_trimmed_paths!( let v = with_no_trimmed_paths!(
args[tcx.generics_of(def_id).parent_count..] args[tcx.generics_of(def_id).parent_count..]
.iter() .iter()
@ -527,7 +526,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
debug!("build: local regions = {}..{}", first_local_index, num_universals); debug!("build: local regions = {}..{}", first_local_index, num_universals);
let yield_ty = match defining_ty { let yield_ty = match defining_ty {
DefiningTy::Coroutine(_, args, _) => Some(args.as_coroutine().yield_ty()), DefiningTy::Coroutine(_, args) => Some(args.as_coroutine().yield_ty()),
_ => None, _ => None,
}; };
@ -562,9 +561,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
match *defining_ty.kind() { match *defining_ty.kind() {
ty::Closure(def_id, args) => DefiningTy::Closure(def_id, args), ty::Closure(def_id, args) => DefiningTy::Closure(def_id, args),
ty::Coroutine(def_id, args, movability) => { ty::Coroutine(def_id, args) => DefiningTy::Coroutine(def_id, args),
DefiningTy::Coroutine(def_id, args, movability)
}
ty::FnDef(def_id, args) => DefiningTy::FnDef(def_id, args), ty::FnDef(def_id, args) => DefiningTy::FnDef(def_id, args),
_ => span_bug!( _ => span_bug!(
tcx.def_span(self.mir_def), tcx.def_span(self.mir_def),
@ -620,7 +617,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
let identity_args = GenericArgs::identity_for_item(tcx, typeck_root_def_id); let identity_args = GenericArgs::identity_for_item(tcx, typeck_root_def_id);
let fr_args = match defining_ty { let fr_args = match defining_ty {
DefiningTy::Closure(_, args) DefiningTy::Closure(_, args)
| DefiningTy::Coroutine(_, args, _) | DefiningTy::Coroutine(_, args)
| DefiningTy::InlineConst(_, args) => { | DefiningTy::InlineConst(_, args) => {
// In the case of closures, we rely on the fact that // In the case of closures, we rely on the fact that
// the first N elements in the ClosureArgs are // the first N elements in the ClosureArgs are
@ -685,11 +682,11 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
) )
} }
DefiningTy::Coroutine(def_id, args, movability) => { DefiningTy::Coroutine(def_id, args) => {
assert_eq!(self.mir_def.to_def_id(), def_id); assert_eq!(self.mir_def.to_def_id(), def_id);
let resume_ty = args.as_coroutine().resume_ty(); let resume_ty = args.as_coroutine().resume_ty();
let output = args.as_coroutine().return_ty(); let output = args.as_coroutine().return_ty();
let coroutine_ty = Ty::new_coroutine(tcx, def_id, args, movability); let coroutine_ty = Ty::new_coroutine(tcx, def_id, args);
let inputs_and_output = let inputs_and_output =
self.infcx.tcx.mk_type_list(&[coroutine_ty, resume_ty, output]); self.infcx.tcx.mk_type_list(&[coroutine_ty, resume_ty, output]);
ty::Binder::dummy(inputs_and_output) ty::Binder::dummy(inputs_and_output)

View file

@ -974,8 +974,8 @@ pub(crate) fn assert_assignable<'tcx>(
} }
} }
} }
(&ty::Coroutine(def_id_a, args_a, mov_a), &ty::Coroutine(def_id_b, args_b, mov_b)) (&ty::Coroutine(def_id_a, args_a), &ty::Coroutine(def_id_b, args_b))
if def_id_a == def_id_b && mov_a == mov_b => if def_id_a == def_id_b =>
{ {
let mut types_a = args_a.types(); let mut types_a = args_a.types();
let mut types_b = args_b.types(); let mut types_b = args_b.types();

View file

@ -98,7 +98,7 @@ fn uncached_gcc_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, layout: TyAndLayout
write!(&mut name, "::{}", def.variant(index).name).unwrap(); write!(&mut name, "::{}", def.variant(index).name).unwrap();
} }
} }
if let (&ty::Coroutine(_, _, _), &Variants::Single { index }) = if let (&ty::Coroutine(_, _), &Variants::Single { index }) =
(layout.ty.kind(), &layout.variants) (layout.ty.kind(), &layout.variants)
{ {
write!(&mut name, "::{}", ty::CoroutineArgs::variant_name(index)).unwrap(); write!(&mut name, "::{}", ty::CoroutineArgs::variant_name(index)).unwrap();

View file

@ -1066,7 +1066,7 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>(
closure_or_coroutine_di_node: &'ll DIType, closure_or_coroutine_di_node: &'ll DIType,
) -> SmallVec<&'ll DIType> { ) -> SmallVec<&'ll DIType> {
let (&def_id, up_var_tys) = match closure_or_coroutine_ty.kind() { let (&def_id, up_var_tys) = match closure_or_coroutine_ty.kind() {
ty::Coroutine(def_id, args, _) => (def_id, args.as_coroutine().prefix_tys()), ty::Coroutine(def_id, args) => (def_id, args.as_coroutine().prefix_tys()),
ty::Closure(def_id, args) => (def_id, args.as_closure().upvar_tys()), ty::Closure(def_id, args) => (def_id, args.as_closure().upvar_tys()),
_ => { _ => {
bug!( bug!(

View file

@ -679,7 +679,7 @@ fn build_union_fields_for_direct_tag_coroutine<'ll, 'tcx>(
}; };
let (coroutine_def_id, coroutine_args) = match coroutine_type_and_layout.ty.kind() { let (coroutine_def_id, coroutine_args) = match coroutine_type_and_layout.ty.kind() {
&ty::Coroutine(def_id, args, _) => (def_id, args.as_coroutine()), &ty::Coroutine(def_id, args) => (def_id, args.as_coroutine()),
_ => unreachable!(), _ => unreachable!(),
}; };

View file

@ -336,7 +336,7 @@ pub fn build_coroutine_variant_struct_type_di_node<'ll, 'tcx>(
let variant_layout = coroutine_type_and_layout.for_variant(cx, variant_index); let variant_layout = coroutine_type_and_layout.for_variant(cx, variant_index);
let coroutine_args = match coroutine_type_and_layout.ty.kind() { let coroutine_args = match coroutine_type_and_layout.ty.kind() {
ty::Coroutine(_, args, _) => args.as_coroutine(), ty::Coroutine(_, args) => args.as_coroutine(),
_ => unreachable!(), _ => unreachable!(),
}; };

View file

@ -135,7 +135,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>(
unique_type_id: UniqueTypeId<'tcx>, unique_type_id: UniqueTypeId<'tcx>,
) -> DINodeCreationResult<'ll> { ) -> DINodeCreationResult<'ll> {
let coroutine_type = unique_type_id.expect_ty(); let coroutine_type = unique_type_id.expect_ty();
let &ty::Coroutine(coroutine_def_id, _, _) = coroutine_type.kind() else { let &ty::Coroutine(coroutine_def_id, _) = coroutine_type.kind() else {
bug!("build_coroutine_di_node() called with non-coroutine type: `{:?}`", coroutine_type) bug!("build_coroutine_di_node() called with non-coroutine type: `{:?}`", coroutine_type)
}; };

View file

@ -54,7 +54,7 @@ fn uncached_llvm_type<'a, 'tcx>(
write!(&mut name, "::{}", def.variant(index).name).unwrap(); write!(&mut name, "::{}", def.variant(index).name).unwrap();
} }
} }
if let (&ty::Coroutine(_, _, _), &Variants::Single { index }) = if let (&ty::Coroutine(_, _), &Variants::Single { index }) =
(layout.ty.kind(), &layout.variants) (layout.ty.kind(), &layout.variants)
{ {
write!(&mut name, "::{}", ty::CoroutineArgs::variant_name(index)).unwrap(); write!(&mut name, "::{}", ty::CoroutineArgs::variant_name(index)).unwrap();

View file

@ -171,7 +171,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
ty::Adt(adt, _) => { ty::Adt(adt, _) => {
adt.discriminants(*self.tcx).find(|(_, var)| var.val == discr_bits) adt.discriminants(*self.tcx).find(|(_, var)| var.val == discr_bits)
} }
ty::Coroutine(def_id, args, _) => { ty::Coroutine(def_id, args) => {
let args = args.as_coroutine(); let args = args.as_coroutine();
args.discriminants(def_id, *self.tcx).find(|(_, var)| var.val == discr_bits) args.discriminants(def_id, *self.tcx).find(|(_, var)| var.val == discr_bits)
} }

View file

@ -85,7 +85,7 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>(
| ty::FnPtr(_) | ty::FnPtr(_)
| ty::Dynamic(_, _, _) | ty::Dynamic(_, _, _)
| ty::Closure(_, _) | ty::Closure(_, _)
| ty::Coroutine(_, _, _) | ty::Coroutine(_, _)
| ty::CoroutineWitness(..) | ty::CoroutineWitness(..)
| ty::Never | ty::Never
| ty::Tuple(_) | ty::Tuple(_)

View file

@ -217,7 +217,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
// Now we know we are projecting to a field, so figure out which one. // Now we know we are projecting to a field, so figure out which one.
match layout.ty.kind() { match layout.ty.kind() {
// coroutines and closures. // coroutines and closures.
ty::Closure(def_id, _) | ty::Coroutine(def_id, _, _) => { ty::Closure(def_id, _) | ty::Coroutine(def_id, _) => {
let mut name = None; let mut name = None;
// FIXME this should be more descriptive i.e. CapturePlace instead of CapturedVar // FIXME this should be more descriptive i.e. CapturePlace instead of CapturedVar
// https://github.com/rust-lang/project-rfc-2229/issues/46 // https://github.com/rust-lang/project-rfc-2229/issues/46

View file

@ -694,7 +694,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
}; };
check_equal(self, location, f_ty); check_equal(self, location, f_ty);
} }
&ty::Coroutine(def_id, args, _) => { &ty::Coroutine(def_id, args) => {
let f_ty = if let Some(var) = parent_ty.variant_index { let f_ty = if let Some(var) = parent_ty.variant_index {
let gen_body = if def_id == self.body.source.def_id() { let gen_body = if def_id == self.body.source.def_id() {
self.body self.body

View file

@ -51,7 +51,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
| ty::FnDef(def_id, args) | ty::FnDef(def_id, args)
| ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, args, .. }) | ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, args, .. })
| ty::Closure(def_id, args) | ty::Closure(def_id, args)
| ty::Coroutine(def_id, args, _) => self.print_def_path(def_id, args), | ty::Coroutine(def_id, args) => self.print_def_path(def_id, args),
ty::Foreign(def_id) => self.print_def_path(def_id, &[]), ty::Foreign(def_id) => self.print_def_path(def_id, &[]),
ty::Alias(ty::Weak, _) => bug!("type_name: unexpected weak projection"), ty::Alias(ty::Weak, _) => bug!("type_name: unexpected weak projection"),

View file

@ -160,12 +160,7 @@ pub(super) fn check_fn<'a, 'tcx>(
)); ));
let (resume_ty, yield_ty) = fcx.resume_yield_tys.unwrap(); let (resume_ty, yield_ty) = fcx.resume_yield_tys.unwrap();
Some(CoroutineTypes { Some(CoroutineTypes { resume_ty, yield_ty, interior })
resume_ty,
yield_ty,
interior,
movability: coroutine_kind.movability(),
})
} else { } else {
None None
}; };

View file

@ -105,8 +105,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
span: self.tcx.def_span(expr_def_id), span: self.tcx.def_span(expr_def_id),
}); });
if let Some(CoroutineTypes { resume_ty, yield_ty, interior, movability }) = coroutine_types if let Some(CoroutineTypes { resume_ty, yield_ty, interior }) = coroutine_types {
{
let coroutine_args = ty::CoroutineArgs::new( let coroutine_args = ty::CoroutineArgs::new(
self.tcx, self.tcx,
ty::CoroutineArgsParts { ty::CoroutineArgsParts {
@ -119,12 +118,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}, },
); );
return Ty::new_coroutine( return Ty::new_coroutine(self.tcx, expr_def_id.to_def_id(), coroutine_args.args);
self.tcx,
expr_def_id.to_def_id(),
coroutine_args.args,
movability,
);
} }
// Tuple up the arguments and insert the resulting function type into // Tuple up the arguments and insert the resulting function type into

View file

@ -304,9 +304,6 @@ struct CoroutineTypes<'tcx> {
/// Types that are captured (see `CoroutineInterior` for more). /// Types that are captured (see `CoroutineInterior` for more).
interior: Ty<'tcx>, interior: Ty<'tcx>,
/// Indicates if the coroutine is movable or static (immovable).
movability: hir::Movability,
} }
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]

View file

@ -172,7 +172,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let ty = self.node_ty(closure_hir_id); let ty = self.node_ty(closure_hir_id);
let (closure_def_id, args) = match *ty.kind() { let (closure_def_id, args) = match *ty.kind() {
ty::Closure(def_id, args) => (def_id, UpvarArgs::Closure(args)), ty::Closure(def_id, args) => (def_id, UpvarArgs::Closure(args)),
ty::Coroutine(def_id, args, _) => (def_id, UpvarArgs::Coroutine(args)), ty::Coroutine(def_id, args) => (def_id, UpvarArgs::Coroutine(args)),
ty::Error(_) => { ty::Error(_) => {
// #51714: skip analysis when we have already encountered type errors // #51714: skip analysis when we have already encountered type errors
return; return;

View file

@ -456,7 +456,7 @@ where
args.as_closure().sig_as_fn_ptr_ty().visit_with(self); args.as_closure().sig_as_fn_ptr_ty().visit_with(self);
} }
ty::Coroutine(_, args, _) => { ty::Coroutine(_, args) => {
// Skip lifetime parameters of the enclosing item(s) // Skip lifetime parameters of the enclosing item(s)
// Also skip the witness type, because that has no free regions. // Also skip the witness type, because that has no free regions.

View file

@ -103,7 +103,7 @@ fn compute_components<'tcx>(
compute_components(tcx, tupled_ty, out, visited); compute_components(tcx, tupled_ty, out, visited);
} }
ty::Coroutine(_, args, _) => { ty::Coroutine(_, args) => {
// Same as the closure case // Same as the closure case
let tupled_ty = args.as_coroutine().tupled_upvars_ty(); let tupled_ty = args.as_coroutine().tupled_upvars_ty();
compute_components(tcx, tupled_ty, out, visited); compute_components(tcx, tupled_ty, out, visited);

View file

@ -240,6 +240,7 @@ provide! { tcx, def_id, other, cdata,
mir_const_qualif => { table } mir_const_qualif => { table }
rendered_const => { table } rendered_const => { table }
asyncness => { table_direct } asyncness => { table_direct }
movability => { table_direct }
fn_arg_names => { table } fn_arg_names => { table }
coroutine_kind => { table_direct } coroutine_kind => { table_direct }
trait_def => { table } trait_def => { table }

View file

@ -1445,6 +1445,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
&& let Some(coroutine_kind) = self.tcx.coroutine_kind(def_id) && let Some(coroutine_kind) = self.tcx.coroutine_kind(def_id)
{ {
self.tables.coroutine_kind.set(def_id.index, Some(coroutine_kind)); self.tables.coroutine_kind.set(def_id.index, Some(coroutine_kind));
self.tables.movability.set(def_id.index, Some(self.tcx.movability(def_id)));
} }
if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind { if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind {
self.encode_info_for_adt(local_id); self.encode_info_for_adt(local_id);

View file

@ -448,6 +448,7 @@ define_tables! {
mir_const_qualif: Table<DefIndex, LazyValue<mir::ConstQualifs>>, mir_const_qualif: Table<DefIndex, LazyValue<mir::ConstQualifs>>,
rendered_const: Table<DefIndex, LazyValue<String>>, rendered_const: Table<DefIndex, LazyValue<String>>,
asyncness: Table<DefIndex, ty::Asyncness>, asyncness: Table<DefIndex, ty::Asyncness>,
movability: Table<DefIndex, hir::Movability>,
fn_arg_names: Table<DefIndex, LazyArray<Ident>>, fn_arg_names: Table<DefIndex, LazyArray<Ident>>,
coroutine_kind: Table<DefIndex, hir::CoroutineKind>, coroutine_kind: Table<DefIndex, hir::CoroutineKind>,
trait_def: Table<DefIndex, LazyValue<ty::TraitDef>>, trait_def: Table<DefIndex, LazyValue<ty::TraitDef>>,

View file

@ -213,6 +213,13 @@ fixed_size_enum! {
} }
} }
fixed_size_enum! {
ty::Movability {
( Movable )
( Static )
}
}
fixed_size_enum! { fixed_size_enum! {
ty::AssocItemContainer { ty::AssocItemContainer {
( TraitContainer ) ( TraitContainer )

View file

@ -1049,7 +1049,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
struct_fmt.finish() struct_fmt.finish()
}), }),
AggregateKind::Coroutine(def_id, _, _) => ty::tls::with(|tcx| { AggregateKind::Coroutine(def_id, _) => ty::tls::with(|tcx| {
let name = format!("{{coroutine@{:?}}}", tcx.def_span(def_id)); let name = format!("{{coroutine@{:?}}}", tcx.def_span(def_id));
let mut struct_fmt = fmt.debug_struct(&name); let mut struct_fmt = fmt.debug_struct(&name);
@ -1304,11 +1304,11 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
self.push(&format!("+ args: {args:#?}")); self.push(&format!("+ args: {args:#?}"));
} }
AggregateKind::Coroutine(def_id, args, movability) => { AggregateKind::Coroutine(def_id, args) => {
self.push("coroutine"); self.push("coroutine");
self.push(&format!("+ def_id: {def_id:?}")); self.push(&format!("+ def_id: {def_id:?}"));
self.push(&format!("+ args: {args:#?}")); self.push(&format!("+ args: {args:#?}"));
self.push(&format!("+ movability: {movability:?}")); self.push(&format!("+ movability: {:?}", self.tcx.movability(def_id)));
} }
AggregateKind::Adt(_, _, _, Some(user_ty), _) => { AggregateKind::Adt(_, _, _, Some(user_ty), _) => {

View file

@ -14,7 +14,6 @@ use crate::ty::{Region, UserTypeAnnotationIndex};
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::{self as hir};
use rustc_hir::{self, CoroutineKind}; use rustc_hir::{self, CoroutineKind};
use rustc_index::IndexVec; use rustc_index::IndexVec;
use rustc_target::abi::{FieldIdx, VariantIdx}; use rustc_target::abi::{FieldIdx, VariantIdx};
@ -1344,7 +1343,7 @@ pub enum AggregateKind<'tcx> {
Adt(DefId, VariantIdx, GenericArgsRef<'tcx>, Option<UserTypeAnnotationIndex>, Option<FieldIdx>), Adt(DefId, VariantIdx, GenericArgsRef<'tcx>, Option<UserTypeAnnotationIndex>, Option<FieldIdx>),
Closure(DefId, GenericArgsRef<'tcx>), Closure(DefId, GenericArgsRef<'tcx>),
Coroutine(DefId, GenericArgsRef<'tcx>, hir::Movability), Coroutine(DefId, GenericArgsRef<'tcx>),
} }
#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)] #[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]

View file

@ -201,9 +201,7 @@ impl<'tcx> Rvalue<'tcx> {
} }
AggregateKind::Adt(did, _, args, _, _) => tcx.type_of(did).instantiate(tcx, args), AggregateKind::Adt(did, _, args, _, _) => tcx.type_of(did).instantiate(tcx, args),
AggregateKind::Closure(did, args) => Ty::new_closure(tcx, did, args), AggregateKind::Closure(did, args) => Ty::new_closure(tcx, did, args),
AggregateKind::Coroutine(did, args, movability) => { AggregateKind::Coroutine(did, args) => Ty::new_coroutine(tcx, did, args),
Ty::new_coroutine(tcx, did, args, movability)
}
}, },
Rvalue::ShallowInitBox(_, ty) => Ty::new_box(tcx, ty), Rvalue::ShallowInitBox(_, ty) => Ty::new_box(tcx, ty),
Rvalue::CopyForDeref(ref place) => place.ty(local_decls, tcx).ty, Rvalue::CopyForDeref(ref place) => place.ty(local_decls, tcx).ty,

View file

@ -736,7 +736,6 @@ macro_rules! make_mir_visitor {
AggregateKind::Coroutine( AggregateKind::Coroutine(
_, _,
coroutine_args, coroutine_args,
_movability,
) => { ) => {
self.visit_args(coroutine_args, location); self.visit_args(coroutine_args, location);
} }

View file

@ -254,6 +254,7 @@ trivial! {
rustc_hir::IsAsync, rustc_hir::IsAsync,
rustc_hir::ItemLocalId, rustc_hir::ItemLocalId,
rustc_hir::LangItem, rustc_hir::LangItem,
rustc_hir::Movability,
rustc_hir::OwnerId, rustc_hir::OwnerId,
rustc_hir::Upvar, rustc_hir::Upvar,
rustc_index::bit_set::FiniteBitSet<u32>, rustc_index::bit_set::FiniteBitSet<u32>,

View file

@ -721,6 +721,11 @@ rustc_queries! {
desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) } desc { |tcx| "computing drop-check constraints for `{}`", tcx.def_path_str(key) }
} }
query movability(key: DefId) -> hir::Movability {
desc { |tcx| "checking if coroutine is movable: `{}`", tcx.def_path_str(key) }
separate_provide_extern
}
/// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate /// Returns `true` if this is a const fn, use the `is_const_fn` to know whether your crate
/// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might
/// not have the feature gate active). /// not have the feature gate active).

View file

@ -128,7 +128,7 @@ pub fn simplify_type<'tcx>(
}, },
ty::Ref(_, _, mutbl) => Some(SimplifiedType::Ref(mutbl)), ty::Ref(_, _, mutbl) => Some(SimplifiedType::Ref(mutbl)),
ty::FnDef(def_id, _) | ty::Closure(def_id, _) => Some(SimplifiedType::Closure(def_id)), ty::FnDef(def_id, _) | ty::Closure(def_id, _) => Some(SimplifiedType::Closure(def_id)),
ty::Coroutine(def_id, _, _) => Some(SimplifiedType::Coroutine(def_id)), ty::Coroutine(def_id, _) => Some(SimplifiedType::Coroutine(def_id)),
ty::CoroutineWitness(def_id, _) => Some(SimplifiedType::CoroutineWitness(def_id)), ty::CoroutineWitness(def_id, _) => Some(SimplifiedType::CoroutineWitness(def_id)),
ty::Never => Some(SimplifiedType::Never), ty::Never => Some(SimplifiedType::Never),
ty::Tuple(tys) => Some(SimplifiedType::Tuple(tys.len())), ty::Tuple(tys) => Some(SimplifiedType::Tuple(tys.len())),

View file

@ -96,7 +96,7 @@ impl FlagComputation {
self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE); self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
} }
ty::Coroutine(_, args, _) => { ty::Coroutine(_, args) => {
let args = args.as_coroutine(); let args = args.as_coroutine();
let should_remove_further_specializable = let should_remove_further_specializable =
!self.flags.contains(TypeFlags::STILL_FURTHER_SPECIALIZABLE); !self.flags.contains(TypeFlags::STILL_FURTHER_SPECIALIZABLE);

View file

@ -689,13 +689,13 @@ fn polymorphize<'tcx>(
Ty::new_closure(self.tcx, def_id, polymorphized_args) Ty::new_closure(self.tcx, def_id, polymorphized_args)
} }
} }
ty::Coroutine(def_id, args, movability) => { ty::Coroutine(def_id, args) => {
let polymorphized_args = let polymorphized_args =
polymorphize(self.tcx, ty::InstanceDef::Item(def_id), args); polymorphize(self.tcx, ty::InstanceDef::Item(def_id), args);
if args == polymorphized_args { if args == polymorphized_args {
ty ty
} else { } else {
Ty::new_coroutine(self.tcx, def_id, polymorphized_args, movability) Ty::new_coroutine(self.tcx, def_id, polymorphized_args)
} }
} }
_ => ty.super_fold_with(self), _ => ty.super_fold_with(self),

View file

@ -906,7 +906,7 @@ where
i, i,
), ),
ty::Coroutine(def_id, args, _) => match this.variants { ty::Coroutine(def_id, args) => match this.variants {
Variants::Single { index } => TyMaybeWithLayout::Ty( Variants::Single { index } => TyMaybeWithLayout::Ty(
args.as_coroutine() args.as_coroutine()
.state_tys(def_id, tcx) .state_tys(def_id, tcx)

View file

@ -153,9 +153,9 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReverseMapper<'tcx> {
Ty::new_closure(self.tcx, def_id, args) Ty::new_closure(self.tcx, def_id, args)
} }
ty::Coroutine(def_id, args, movability) => { ty::Coroutine(def_id, args) => {
let args = self.fold_closure_args(def_id, args); let args = self.fold_closure_args(def_id, args);
Ty::new_coroutine(self.tcx, def_id, args, movability) Ty::new_coroutine(self.tcx, def_id, args)
} }
ty::CoroutineWitness(def_id, args) => { ty::CoroutineWitness(def_id, args) => {

View file

@ -86,6 +86,7 @@ trivially_parameterized_over_tcx! {
rustc_hir::CoroutineKind, rustc_hir::CoroutineKind,
rustc_hir::IsAsync, rustc_hir::IsAsync,
rustc_hir::LangItem, rustc_hir::LangItem,
rustc_hir::Movability,
rustc_hir::def::DefKind, rustc_hir::def::DefKind,
rustc_hir::def::DocLinkResMap, rustc_hir::def::DocLinkResMap,
rustc_hir::def_id::DefId, rustc_hir::def_id::DefId,

View file

@ -259,7 +259,7 @@ fn characteristic_def_id_of_type_cached<'a>(
ty::FnDef(def_id, _) ty::FnDef(def_id, _)
| ty::Closure(def_id, _) | ty::Closure(def_id, _)
| ty::Coroutine(def_id, _, _) | ty::Coroutine(def_id, _)
| ty::CoroutineWitness(def_id, _) | ty::CoroutineWitness(def_id, _)
| ty::Foreign(def_id) => Some(def_id), | ty::Foreign(def_id) => Some(def_id),

View file

@ -783,14 +783,14 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
} }
} }
ty::Str => p!("str"), ty::Str => p!("str"),
ty::Coroutine(did, args, movability) => { ty::Coroutine(did, args) => {
p!(write("{{")); p!(write("{{"));
let coroutine_kind = self.tcx().coroutine_kind(did).unwrap(); let coroutine_kind = self.tcx().coroutine_kind(did).unwrap();
let should_print_movability = self.should_print_verbose() let should_print_movability = self.should_print_verbose()
|| matches!(coroutine_kind, hir::CoroutineKind::Coroutine(_)); || matches!(coroutine_kind, hir::CoroutineKind::Coroutine(_));
if should_print_movability { if should_print_movability {
match movability { match self.tcx().movability(did) {
hir::Movability::Movable => {} hir::Movability::Movable => {}
hir::Movability::Static => p!("static "), hir::Movability::Static => p!("static "),
} }
@ -1055,7 +1055,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
&& assoc.trait_container(tcx) == tcx.lang_items().coroutine_trait() && assoc.trait_container(tcx) == tcx.lang_items().coroutine_trait()
&& assoc.name == rustc_span::sym::Return && assoc.name == rustc_span::sym::Return
{ {
if let ty::Coroutine(_, args, _) = args.type_at(0).kind() { if let ty::Coroutine(_, args) = args.type_at(0).kind() {
let return_ty = args.as_coroutine().return_ty(); let return_ty = args.as_coroutine().return_ty();
if !return_ty.is_ty_var() { if !return_ty.is_ty_var() {
return_ty.into() return_ty.into()

View file

@ -455,14 +455,12 @@ pub fn structurally_relate_tys<'tcx, R: TypeRelation<'tcx>>(
Ok(Ty::new_dynamic(tcx, relation.relate(a_obj, b_obj)?, region_bound, a_repr)) Ok(Ty::new_dynamic(tcx, relation.relate(a_obj, b_obj)?, region_bound, a_repr))
} }
(&ty::Coroutine(a_id, a_args, movability), &ty::Coroutine(b_id, b_args, _)) (&ty::Coroutine(a_id, a_args), &ty::Coroutine(b_id, b_args)) if a_id == b_id => {
if a_id == b_id =>
{
// All Coroutine types with the same id represent // All Coroutine types with the same id represent
// the (anonymous) type of the same coroutine expression. So // the (anonymous) type of the same coroutine expression. So
// all of their regions should be equated. // all of their regions should be equated.
let args = relate_args_invariantly(relation, a_args, b_args)?; let args = relate_args_invariantly(relation, a_args, b_args)?;
Ok(Ty::new_coroutine(tcx, a_id, args, movability)) Ok(Ty::new_coroutine(tcx, a_id, args))
} }
(&ty::CoroutineWitness(a_id, a_args), &ty::CoroutineWitness(b_id, b_args)) (&ty::CoroutineWitness(a_id, a_args), &ty::CoroutineWitness(b_id, b_args))

View file

@ -578,9 +578,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for Ty<'tcx> {
ty::Ref(r, ty, mutbl) => { ty::Ref(r, ty, mutbl) => {
ty::Ref(r.try_fold_with(folder)?, ty.try_fold_with(folder)?, mutbl) ty::Ref(r.try_fold_with(folder)?, ty.try_fold_with(folder)?, mutbl)
} }
ty::Coroutine(did, args, movability) => { ty::Coroutine(did, args) => ty::Coroutine(did, args.try_fold_with(folder)?),
ty::Coroutine(did, args.try_fold_with(folder)?, movability)
}
ty::CoroutineWitness(did, args) => { ty::CoroutineWitness(did, args) => {
ty::CoroutineWitness(did, args.try_fold_with(folder)?) ty::CoroutineWitness(did, args.try_fold_with(folder)?)
} }
@ -630,7 +628,7 @@ impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for Ty<'tcx> {
r.visit_with(visitor)?; r.visit_with(visitor)?;
ty.visit_with(visitor) ty.visit_with(visitor)
} }
ty::Coroutine(_did, ref args, _) => args.visit_with(visitor), ty::Coroutine(_did, ref args) => args.visit_with(visitor),
ty::CoroutineWitness(_did, ref args) => args.visit_with(visitor), ty::CoroutineWitness(_did, ref args) => args.visit_with(visitor),
ty::Closure(_did, ref args) => args.visit_with(visitor), ty::Closure(_did, ref args) => args.visit_with(visitor),
ty::Alias(_, ref data) => data.visit_with(visitor), ty::Alias(_, ref data) => data.visit_with(visitor),

View file

@ -2168,14 +2168,13 @@ impl<'tcx> Ty<'tcx> {
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
def_id: DefId, def_id: DefId,
coroutine_args: GenericArgsRef<'tcx>, coroutine_args: GenericArgsRef<'tcx>,
movability: hir::Movability,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
debug_assert_eq!( debug_assert_eq!(
coroutine_args.len(), coroutine_args.len(),
tcx.generics_of(tcx.typeck_root_def_id(def_id)).count() + 5, tcx.generics_of(tcx.typeck_root_def_id(def_id)).count() + 5,
"coroutine constructed with incorrect number of substitutions" "coroutine constructed with incorrect number of substitutions"
); );
Ty::new(tcx, Coroutine(def_id, coroutine_args, movability)) Ty::new(tcx, Coroutine(def_id, coroutine_args))
} }
#[inline] #[inline]
@ -2656,7 +2655,7 @@ impl<'tcx> Ty<'tcx> {
pub fn variant_range(self, tcx: TyCtxt<'tcx>) -> Option<Range<VariantIdx>> { pub fn variant_range(self, tcx: TyCtxt<'tcx>) -> Option<Range<VariantIdx>> {
match self.kind() { match self.kind() {
TyKind::Adt(adt, _) => Some(adt.variant_range()), TyKind::Adt(adt, _) => Some(adt.variant_range()),
TyKind::Coroutine(def_id, args, _) => { TyKind::Coroutine(def_id, args) => {
Some(args.as_coroutine().variant_range(*def_id, tcx)) Some(args.as_coroutine().variant_range(*def_id, tcx))
} }
_ => None, _ => None,
@ -2677,7 +2676,7 @@ impl<'tcx> Ty<'tcx> {
TyKind::Adt(adt, _) if adt.is_enum() => { TyKind::Adt(adt, _) if adt.is_enum() => {
Some(adt.discriminant_for_variant(tcx, variant_index)) Some(adt.discriminant_for_variant(tcx, variant_index))
} }
TyKind::Coroutine(def_id, args, _) => { TyKind::Coroutine(def_id, args) => {
Some(args.as_coroutine().discriminant_for_variant(*def_id, tcx, variant_index)) Some(args.as_coroutine().discriminant_for_variant(*def_id, tcx, variant_index))
} }
_ => None, _ => None,
@ -2688,7 +2687,7 @@ impl<'tcx> Ty<'tcx> {
pub fn discriminant_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { pub fn discriminant_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
match self.kind() { match self.kind() {
ty::Adt(adt, _) if adt.is_enum() => adt.repr().discr_type().to_ty(tcx), ty::Adt(adt, _) if adt.is_enum() => adt.repr().discr_type().to_ty(tcx),
ty::Coroutine(_, args, _) => args.as_coroutine().discr_ty(tcx), ty::Coroutine(_, args) => args.as_coroutine().discr_ty(tcx),
ty::Param(_) | ty::Alias(..) | ty::Infer(ty::TyVar(_)) => { ty::Param(_) | ty::Alias(..) | ty::Infer(ty::TyVar(_)) => {
let assoc_items = tcx.associated_item_def_ids( let assoc_items = tcx.associated_item_def_ids(
@ -2983,7 +2982,7 @@ impl<'tcx> Ty<'tcx> {
| FnPtr(_) | FnPtr(_)
| Dynamic(_, _, _) | Dynamic(_, _, _)
| Closure(_, _) | Closure(_, _)
| Coroutine(_, _, _) | Coroutine(_, _)
| CoroutineWitness(..) | CoroutineWitness(..)
| Never | Never
| Tuple(_) => true, | Tuple(_) => true,

View file

@ -189,7 +189,7 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>)
} }
ty::Adt(_, args) ty::Adt(_, args)
| ty::Closure(_, args) | ty::Closure(_, args)
| ty::Coroutine(_, args, _) | ty::Coroutine(_, args)
| ty::CoroutineWitness(_, args) | ty::CoroutineWitness(_, args)
| ty::FnDef(_, args) => { | ty::FnDef(_, args) => {
stack.extend(args.iter().rev()); stack.extend(args.iter().rev());

View file

@ -387,8 +387,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
closure_id, closure_id,
args, args,
ref upvars, ref upvars,
movability,
ref fake_reads, ref fake_reads,
movability: _,
}) => { }) => {
// Convert the closure fake reads, if any, from `ExprRef` to mir `Place` // Convert the closure fake reads, if any, from `ExprRef` to mir `Place`
// and push the fake reads. // and push the fake reads.
@ -474,10 +474,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let result = match args { let result = match args {
UpvarArgs::Coroutine(args) => { UpvarArgs::Coroutine(args) => {
// We implicitly set the discriminant to 0. See Box::new(AggregateKind::Coroutine(closure_id.to_def_id(), args))
// librustc_mir/transform/deaggregator.rs for details.
let movability = movability.unwrap();
Box::new(AggregateKind::Coroutine(closure_id.to_def_id(), args, movability))
} }
UpvarArgs::Closure(args) => { UpvarArgs::Closure(args) => {
Box::new(AggregateKind::Closure(closure_id.to_def_id(), args)) Box::new(AggregateKind::Closure(closure_id.to_def_id(), args))

View file

@ -646,7 +646,7 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
} }
DefKind::Closure if coroutine_kind.is_some() => { DefKind::Closure if coroutine_kind.is_some() => {
let coroutine_ty = tcx.type_of(def_id).instantiate_identity(); let coroutine_ty = tcx.type_of(def_id).instantiate_identity();
let ty::Coroutine(_, args, _) = coroutine_ty.kind() else { let ty::Coroutine(_, args) = coroutine_ty.kind() else {
bug!("expected type of coroutine-like closure to be a coroutine") bug!("expected type of coroutine-like closure to be a coroutine")
}; };
let args = args.as_coroutine(); let args = args.as_coroutine();
@ -813,7 +813,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let upvar_args = match closure_ty.kind() { let upvar_args = match closure_ty.kind() {
ty::Closure(_, args) => ty::UpvarArgs::Closure(args), ty::Closure(_, args) => ty::UpvarArgs::Closure(args),
ty::Coroutine(_, args, _) => ty::UpvarArgs::Coroutine(args), ty::Coroutine(_, args) => ty::UpvarArgs::Coroutine(args),
_ => return, _ => return,
}; };

View file

@ -552,8 +552,8 @@ impl<'tcx> Cx<'tcx> {
let closure_ty = self.typeck_results().expr_ty(expr); let closure_ty = self.typeck_results().expr_ty(expr);
let (def_id, args, movability) = match *closure_ty.kind() { let (def_id, args, movability) = match *closure_ty.kind() {
ty::Closure(def_id, args) => (def_id, UpvarArgs::Closure(args), None), ty::Closure(def_id, args) => (def_id, UpvarArgs::Closure(args), None),
ty::Coroutine(def_id, args, movability) => { ty::Coroutine(def_id, args) => {
(def_id, UpvarArgs::Coroutine(args), Some(movability)) (def_id, UpvarArgs::Coroutine(args), Some(tcx.movability(def_id)))
} }
_ => { _ => {
span_bug!(expr.span, "closure expr w/o closure type: {:?}", closure_ty); span_bug!(expr.span, "closure expr w/o closure type: {:?}", closure_ty);

View file

@ -862,7 +862,7 @@ where
// This should only happen for the self argument on the resume function. // This should only happen for the self argument on the resume function.
// It effectively only contains upvars until the coroutine transformation runs. // It effectively only contains upvars until the coroutine transformation runs.
// See librustc_body/transform/coroutine.rs for more details. // See librustc_body/transform/coroutine.rs for more details.
ty::Coroutine(_, args, _) => self.open_drop_for_tuple(args.as_coroutine().upvar_tys()), ty::Coroutine(_, args) => self.open_drop_for_tuple(args.as_coroutine().upvar_tys()),
ty::Tuple(fields) => self.open_drop_for_tuple(fields), ty::Tuple(fields) => self.open_drop_for_tuple(fields),
ty::Adt(def, args) => self.open_drop_for_adt(*def, args), ty::Adt(def, args) => self.open_drop_for_adt(*def, args),
ty::Dynamic(..) => self.complete_drop(self.succ, self.unwind), ty::Dynamic(..) => self.complete_drop(self.succ, self.unwind),

View file

@ -155,7 +155,7 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
| ty::FnPtr(_) | ty::FnPtr(_)
| ty::Dynamic(_, _, _) | ty::Dynamic(_, _, _)
| ty::Closure(_, _) | ty::Closure(_, _)
| ty::Coroutine(_, _, _) | ty::Coroutine(_, _)
| ty::CoroutineWitness(..) | ty::CoroutineWitness(..)
| ty::Never | ty::Never
| ty::Tuple(_) | ty::Tuple(_)
@ -177,7 +177,7 @@ impl<'b, 'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> Gatherer<'b, 'a, 'tcx, F> {
union_path.get_or_insert(base); union_path.get_or_insert(base);
} }
} }
ty::Closure(_, _) | ty::Coroutine(_, _, _) | ty::Tuple(_) => (), ty::Closure(_, _) | ty::Coroutine(_, _) | ty::Tuple(_) => (),
ty::Bool ty::Bool
| ty::Char | ty::Char
| ty::Int(_) | ty::Int(_)

View file

@ -128,7 +128,7 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> {
), ),
} }
} }
&AggregateKind::Closure(def_id, _) | &AggregateKind::Coroutine(def_id, _, _) => { &AggregateKind::Closure(def_id, _) | &AggregateKind::Coroutine(def_id, _) => {
let def_id = def_id.expect_local(); let def_id = def_id.expect_local();
let UnsafetyCheckResult { violations, used_unsafe_blocks, .. } = let UnsafetyCheckResult { violations, used_unsafe_blocks, .. } =
self.tcx.unsafety_check_result(def_id); self.tcx.unsafety_check_result(def_id);

View file

@ -1565,7 +1565,7 @@ pub(crate) fn mir_coroutine_witnesses<'tcx>(
let coroutine_ty = body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty; let coroutine_ty = body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty;
let movable = match *coroutine_ty.kind() { let movable = match *coroutine_ty.kind() {
ty::Coroutine(_, _, movability) => movability == hir::Movability::Movable, ty::Coroutine(def_id, _) => tcx.movability(def_id) == hir::Movability::Movable,
ty::Error(_) => return None, ty::Error(_) => return None,
_ => span_bug!(body.span, "unexpected coroutine type {}", coroutine_ty), _ => span_bug!(body.span, "unexpected coroutine type {}", coroutine_ty),
}; };
@ -1600,9 +1600,9 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
// Get the discriminant type and args which typeck computed // Get the discriminant type and args which typeck computed
let (discr_ty, movable) = match *coroutine_ty.kind() { let (discr_ty, movable) = match *coroutine_ty.kind() {
ty::Coroutine(_, args, movability) => { ty::Coroutine(def_id, args) => {
let args = args.as_coroutine(); let args = args.as_coroutine();
(args.discr_ty(tcx), movability == hir::Movability::Movable) (args.discr_ty(tcx), tcx.movability(def_id) == hir::Movability::Movable)
} }
_ => { _ => {
tcx.dcx().span_delayed_bug( tcx.dcx().span_delayed_bug(

View file

@ -91,7 +91,7 @@ fn bcb_to_initial_coverage_spans<'a, 'tcx>(
fn is_closure(statement: &Statement<'_>) -> bool { fn is_closure(statement: &Statement<'_>) -> bool {
match statement.kind { match statement.kind {
StatementKind::Assign(box (_, Rvalue::Aggregate(box ref agg_kind, _))) => match agg_kind { StatementKind::Assign(box (_, Rvalue::Aggregate(box ref agg_kind, _))) => match agg_kind {
AggregateKind::Closure(_, _) | AggregateKind::Coroutine(_, _, _) => true, AggregateKind::Closure(_, _) | AggregateKind::Coroutine(_, _) => true,
_ => false, _ => false,
}, },
_ => false, _ => false,

View file

@ -850,7 +850,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
assert!(!fields.is_empty()); assert!(!fields.is_empty());
(AggregateTy::Tuple, FIRST_VARIANT) (AggregateTy::Tuple, FIRST_VARIANT)
} }
AggregateKind::Closure(did, substs) | AggregateKind::Coroutine(did, substs, _) => { AggregateKind::Closure(did, substs) | AggregateKind::Coroutine(did, substs) => {
(AggregateTy::Def(did, substs), FIRST_VARIANT) (AggregateTy::Def(did, substs), FIRST_VARIANT)
} }
AggregateKind::Adt(did, variant_index, substs, _, None) => { AggregateKind::Adt(did, variant_index, substs, _, None) => {

View file

@ -69,7 +69,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'
ty::InstanceDef::DropGlue(def_id, ty) => { ty::InstanceDef::DropGlue(def_id, ty) => {
// FIXME(#91576): Drop shims for coroutines aren't subject to the MIR passes at the end // FIXME(#91576): Drop shims for coroutines aren't subject to the MIR passes at the end
// of this function. Is this intentional? // of this function. Is this intentional?
if let Some(ty::Coroutine(coroutine_def_id, args, _)) = ty.map(Ty::kind) { if let Some(ty::Coroutine(coroutine_def_id, args)) = ty.map(Ty::kind) {
let body = tcx.optimized_mir(*coroutine_def_id).coroutine_drop().unwrap(); let body = tcx.optimized_mir(*coroutine_def_id).coroutine_drop().unwrap();
let mut body = EarlyBinder::bind(body.clone()).instantiate(tcx, args); let mut body = EarlyBinder::bind(body.clone()).instantiate(tcx, args);
debug!("make_shim({:?}) = {:?}", instance, body); debug!("make_shim({:?}) = {:?}", instance, body);
@ -394,7 +394,8 @@ fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -
_ if is_copy => builder.copy_shim(), _ if is_copy => builder.copy_shim(),
ty::Closure(_, args) => builder.tuple_like_shim(dest, src, args.as_closure().upvar_tys()), ty::Closure(_, args) => builder.tuple_like_shim(dest, src, args.as_closure().upvar_tys()),
ty::Tuple(..) => builder.tuple_like_shim(dest, src, self_ty.tuple_fields()), ty::Tuple(..) => builder.tuple_like_shim(dest, src, self_ty.tuple_fields()),
ty::Coroutine(coroutine_def_id, args, hir::Movability::Movable) => { ty::Coroutine(coroutine_def_id, args) => {
assert_eq!(tcx.movability(coroutine_def_id), hir::Movability::Movable);
builder.coroutine_shim(dest, src, *coroutine_def_id, args.as_coroutine()) builder.coroutine_shim(dest, src, *coroutine_def_id, args.as_coroutine())
} }
_ => bug!("clone shim for `{:?}` which is not `Copy` and is not an aggregate", self_ty), _ => bug!("clone shim for `{:?}` which is not `Copy` and is not an aggregate", self_ty),

View file

@ -333,7 +333,7 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I>
| ty::FnPtr(_) | ty::FnPtr(_)
| ty::Dynamic(_, _, _) | ty::Dynamic(_, _, _)
| ty::Closure(_, _) | ty::Closure(_, _)
| ty::Coroutine(_, _, _) | ty::Coroutine(_, _)
| ty::CoroutineWitness(..) | ty::CoroutineWitness(..)
| ty::Never | ty::Never
| ty::Tuple(_) | ty::Tuple(_)

View file

@ -366,7 +366,7 @@ impl<'p, 'tcx> RustcMatchCheckCtxt<'p, 'tcx> {
| ty::FnPtr(_) | ty::FnPtr(_)
| ty::Dynamic(_, _, _) | ty::Dynamic(_, _, _)
| ty::Closure(_, _) | ty::Closure(_, _)
| ty::Coroutine(_, _, _) | ty::Coroutine(_, _)
| ty::Alias(_, _) | ty::Alias(_, _)
| ty::Param(_) | ty::Param(_)
| ty::Error(_) => ConstructorSet::Unlistable, | ty::Error(_) => ConstructorSet::Unlistable,

View file

@ -104,11 +104,9 @@ impl<'tcx> RustcInternal<'tcx> for RigidTy {
RigidTy::Closure(def, args) => { RigidTy::Closure(def, args) => {
rustc_ty::TyKind::Closure(def.0.internal(tables), args.internal(tables)) rustc_ty::TyKind::Closure(def.0.internal(tables), args.internal(tables))
} }
RigidTy::Coroutine(def, args, mov) => rustc_ty::TyKind::Coroutine( RigidTy::Coroutine(def, args) => {
def.0.internal(tables), rustc_ty::TyKind::Coroutine(def.0.internal(tables), args.internal(tables))
args.internal(tables), }
mov.internal(tables),
),
RigidTy::CoroutineWitness(def, args) => { RigidTy::CoroutineWitness(def, args) => {
rustc_ty::TyKind::CoroutineWitness(def.0.internal(tables), args.internal(tables)) rustc_ty::TyKind::CoroutineWitness(def.0.internal(tables), args.internal(tables))
} }

View file

@ -531,11 +531,10 @@ impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> {
generic_arg.stable(tables), generic_arg.stable(tables),
) )
} }
mir::AggregateKind::Coroutine(def_id, generic_arg, movability) => { mir::AggregateKind::Coroutine(def_id, generic_arg) => {
stable_mir::mir::AggregateKind::Coroutine( stable_mir::mir::AggregateKind::Coroutine(
tables.coroutine_def(*def_id), tables.coroutine_def(*def_id),
generic_arg.stable(tables), generic_arg.stable(tables),
movability.stable(tables),
) )
} }
} }

View file

@ -386,10 +386,9 @@ impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> {
tables.closure_def(*def_id), tables.closure_def(*def_id),
generic_args.stable(tables), generic_args.stable(tables),
)), )),
ty::Coroutine(def_id, generic_args, movability) => TyKind::RigidTy(RigidTy::Coroutine( ty::Coroutine(def_id, generic_args) => TyKind::RigidTy(RigidTy::Coroutine(
tables.coroutine_def(*def_id), tables.coroutine_def(*def_id),
generic_args.stable(tables), generic_args.stable(tables),
movability.stable(tables),
)), )),
ty::Never => TyKind::RigidTy(RigidTy::Never), ty::Never => TyKind::RigidTy(RigidTy::Never),
ty::Tuple(fields) => { ty::Tuple(fields) => {

View file

@ -211,7 +211,7 @@ impl<'tcx> Printer<'tcx> for SymbolPrinter<'tcx> {
ty::FnDef(def_id, args) ty::FnDef(def_id, args)
| ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, args, .. }) | ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, args, .. })
| ty::Closure(def_id, args) | ty::Closure(def_id, args)
| ty::Coroutine(def_id, args, _) => self.print_def_path(def_id, args), | ty::Coroutine(def_id, args) => self.print_def_path(def_id, args),
// The `pretty_print_type` formatting of array size depends on // The `pretty_print_type` formatting of array size depends on
// -Zverbose-internals flag, so we cannot reuse it here. // -Zverbose-internals flag, so we cannot reuse it here.

View file

@ -895,8 +895,8 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
ty = Ty::new_closure(tcx, *def_id, transform_args(tcx, args, options)); ty = Ty::new_closure(tcx, *def_id, transform_args(tcx, args, options));
} }
ty::Coroutine(def_id, args, movability) => { ty::Coroutine(def_id, args) => {
ty = Ty::new_coroutine(tcx, *def_id, transform_args(tcx, args, options), *movability); ty = Ty::new_coroutine(tcx, *def_id, transform_args(tcx, args, options));
} }
ty::Ref(region, ty0, ..) => { ty::Ref(region, ty0, ..) => {

View file

@ -427,7 +427,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
| ty::FnDef(def_id, args) | ty::FnDef(def_id, args)
| ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, args, .. }) | ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, args, .. })
| ty::Closure(def_id, args) | ty::Closure(def_id, args)
| ty::Coroutine(def_id, args, _) => { | ty::Coroutine(def_id, args) => {
self.print_def_path(def_id, args)?; self.print_def_path(def_id, args)?;
} }
ty::Foreign(def_id) => { ty::Foreign(def_id) => {

View file

@ -432,7 +432,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
| ty::FnPtr(_) | ty::FnPtr(_)
| ty::Dynamic(_, _, _) | ty::Dynamic(_, _, _)
| ty::Closure(_, _) | ty::Closure(_, _)
| ty::Coroutine(_, _, _) | ty::Coroutine(_, _)
| ty::Never | ty::Never
| ty::Tuple(_) => { | ty::Tuple(_) => {
let simp = let simp =

View file

@ -57,7 +57,7 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<'tcx>(
ty::Closure(_, args) => Ok(vec![args.as_closure().tupled_upvars_ty()]), ty::Closure(_, args) => Ok(vec![args.as_closure().tupled_upvars_ty()]),
ty::Coroutine(_, args, _) => { ty::Coroutine(_, args) => {
let coroutine_args = args.as_coroutine(); let coroutine_args = args.as_coroutine();
Ok(vec![coroutine_args.tupled_upvars_ty(), coroutine_args.witness()]) Ok(vec![coroutine_args.tupled_upvars_ty(), coroutine_args.witness()])
} }
@ -177,7 +177,6 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>(
ty::Dynamic(..) ty::Dynamic(..)
| ty::Str | ty::Str
| ty::Slice(_) | ty::Slice(_)
| ty::Coroutine(_, _, Movability::Static)
| ty::Foreign(..) | ty::Foreign(..)
| ty::Ref(_, _, Mutability::Mut) | ty::Ref(_, _, Mutability::Mut)
| ty::Adt(_, _) | ty::Adt(_, _)
@ -194,14 +193,17 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>(
ty::Closure(_, args) => Ok(vec![args.as_closure().tupled_upvars_ty()]), ty::Closure(_, args) => Ok(vec![args.as_closure().tupled_upvars_ty()]),
ty::Coroutine(_, args, Movability::Movable) => { ty::Coroutine(def_id, args) => match ecx.tcx().movability(def_id) {
if ecx.tcx().features().coroutine_clone { Movability::Static => Err(NoSolution),
let coroutine = args.as_coroutine(); Movability::Movable => {
Ok(vec![coroutine.tupled_upvars_ty(), coroutine.witness()]) if ecx.tcx().features().coroutine_clone {
} else { let coroutine = args.as_coroutine();
Err(NoSolution) Ok(vec![coroutine.tupled_upvars_ty(), coroutine.witness()])
} else {
Err(NoSolution)
}
} }
} },
ty::CoroutineWitness(def_id, args) => Ok(ecx ty::CoroutineWitness(def_id, args) => Ok(ecx
.tcx() .tcx()
@ -278,7 +280,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<'tcx>(
| ty::RawPtr(_) | ty::RawPtr(_)
| ty::Ref(_, _, _) | ty::Ref(_, _, _)
| ty::Dynamic(_, _, _) | ty::Dynamic(_, _, _)
| ty::Coroutine(_, _, _) | ty::Coroutine(_, _)
| ty::CoroutineWitness(..) | ty::CoroutineWitness(..)
| ty::Never | ty::Never
| ty::Tuple(_) | ty::Tuple(_)

View file

@ -468,7 +468,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
goal: Goal<'tcx, Self>, goal: Goal<'tcx, Self>,
) -> QueryResult<'tcx> { ) -> QueryResult<'tcx> {
let self_ty = goal.predicate.self_ty(); let self_ty = goal.predicate.self_ty();
let ty::Coroutine(def_id, args, _) = *self_ty.kind() else { let ty::Coroutine(def_id, args) = *self_ty.kind() else {
return Err(NoSolution); return Err(NoSolution);
}; };
@ -499,7 +499,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
goal: Goal<'tcx, Self>, goal: Goal<'tcx, Self>,
) -> QueryResult<'tcx> { ) -> QueryResult<'tcx> {
let self_ty = goal.predicate.self_ty(); let self_ty = goal.predicate.self_ty();
let ty::Coroutine(def_id, args, _) = *self_ty.kind() else { let ty::Coroutine(def_id, args) = *self_ty.kind() else {
return Err(NoSolution); return Err(NoSolution);
}; };
@ -530,7 +530,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
goal: Goal<'tcx, Self>, goal: Goal<'tcx, Self>,
) -> QueryResult<'tcx> { ) -> QueryResult<'tcx> {
let self_ty = goal.predicate.self_ty(); let self_ty = goal.predicate.self_ty();
let ty::Coroutine(def_id, args, _) = *self_ty.kind() else { let ty::Coroutine(def_id, args) = *self_ty.kind() else {
return Err(NoSolution); return Err(NoSolution);
}; };
@ -564,7 +564,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
goal: Goal<'tcx, Self>, goal: Goal<'tcx, Self>,
) -> QueryResult<'tcx> { ) -> QueryResult<'tcx> {
let self_ty = goal.predicate.self_ty(); let self_ty = goal.predicate.self_ty();
let ty::Coroutine(def_id, args, _) = *self_ty.kind() else { let ty::Coroutine(def_id, args) = *self_ty.kind() else {
return Err(NoSolution); return Err(NoSolution);
}; };

View file

@ -337,7 +337,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
return Err(NoSolution); return Err(NoSolution);
} }
let ty::Coroutine(def_id, _, _) = *goal.predicate.self_ty().kind() else { let ty::Coroutine(def_id, _) = *goal.predicate.self_ty().kind() else {
return Err(NoSolution); return Err(NoSolution);
}; };
@ -361,7 +361,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
return Err(NoSolution); return Err(NoSolution);
} }
let ty::Coroutine(def_id, _, _) = *goal.predicate.self_ty().kind() else { let ty::Coroutine(def_id, _) = *goal.predicate.self_ty().kind() else {
return Err(NoSolution); return Err(NoSolution);
}; };
@ -385,7 +385,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
return Err(NoSolution); return Err(NoSolution);
} }
let ty::Coroutine(def_id, _, _) = *goal.predicate.self_ty().kind() else { let ty::Coroutine(def_id, _) = *goal.predicate.self_ty().kind() else {
return Err(NoSolution); return Err(NoSolution);
}; };
@ -410,7 +410,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
} }
let self_ty = goal.predicate.self_ty(); let self_ty = goal.predicate.self_ty();
let ty::Coroutine(def_id, args, _) = *self_ty.kind() else { let ty::Coroutine(def_id, args) = *self_ty.kind() else {
return Err(NoSolution); return Err(NoSolution);
}; };
@ -927,10 +927,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
// Coroutines have one special built-in candidate, `Unpin`, which // Coroutines have one special built-in candidate, `Unpin`, which
// takes precedence over the structural auto trait candidate being // takes precedence over the structural auto trait candidate being
// assembled. // assembled.
ty::Coroutine(_, _, movability) ty::Coroutine(def_id, _)
if Some(goal.predicate.def_id()) == self.tcx().lang_items().unpin_trait() => if Some(goal.predicate.def_id()) == self.tcx().lang_items().unpin_trait() =>
{ {
match movability { match self.tcx().movability(def_id) {
Movability::Static => Some(Err(NoSolution)), Movability::Static => Some(Err(NoSolution)),
Movability::Movable => { Movability::Movable => {
Some(self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)) Some(self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes))
@ -959,7 +959,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
| ty::FnDef(_, _) | ty::FnDef(_, _)
| ty::FnPtr(_) | ty::FnPtr(_)
| ty::Closure(_, _) | ty::Closure(_, _)
| ty::Coroutine(_, _, _) | ty::Coroutine(_, _)
| ty::CoroutineWitness(..) | ty::CoroutineWitness(..)
| ty::Never | ty::Never
| ty::Tuple(_) | ty::Tuple(_)

View file

@ -3406,7 +3406,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
} }
err.note(msg.trim_end_matches(", ").to_string()) err.note(msg.trim_end_matches(", ").to_string())
} }
ty::Coroutine(def_id, _, _) => { ty::Coroutine(def_id, _) => {
let sp = self.tcx.def_span(def_id); let sp = self.tcx.def_span(def_id);
// Special-case this to say "async block" instead of `[static coroutine]`. // Special-case this to say "async block" instead of `[static coroutine]`.

View file

@ -2083,7 +2083,7 @@ fn confirm_coroutine_candidate<'cx, 'tcx>(
nested: Vec<PredicateObligation<'tcx>>, nested: Vec<PredicateObligation<'tcx>>,
) -> Progress<'tcx> { ) -> Progress<'tcx> {
let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty()); let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
let ty::Coroutine(_, args, _) = self_ty.kind() else { let ty::Coroutine(_, args) = self_ty.kind() else {
unreachable!( unreachable!(
"expected coroutine self type for built-in coroutine candidate, found {self_ty}" "expected coroutine self type for built-in coroutine candidate, found {self_ty}"
) )
@ -2138,7 +2138,7 @@ fn confirm_future_candidate<'cx, 'tcx>(
nested: Vec<PredicateObligation<'tcx>>, nested: Vec<PredicateObligation<'tcx>>,
) -> Progress<'tcx> { ) -> Progress<'tcx> {
let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty()); let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
let ty::Coroutine(_, args, _) = self_ty.kind() else { let ty::Coroutine(_, args) = self_ty.kind() else {
unreachable!( unreachable!(
"expected coroutine self type for built-in async future candidate, found {self_ty}" "expected coroutine self type for built-in async future candidate, found {self_ty}"
) )
@ -2182,7 +2182,7 @@ fn confirm_iterator_candidate<'cx, 'tcx>(
nested: Vec<PredicateObligation<'tcx>>, nested: Vec<PredicateObligation<'tcx>>,
) -> Progress<'tcx> { ) -> Progress<'tcx> {
let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty()); let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty());
let ty::Coroutine(_, args, _) = self_ty.kind() else { let ty::Coroutine(_, args) = self_ty.kind() else {
unreachable!("expected coroutine self type for built-in gen candidate, found {self_ty}") unreachable!("expected coroutine self type for built-in gen candidate, found {self_ty}")
}; };
let gen_sig = args.as_coroutine().sig(); let gen_sig = args.as_coroutine().sig();
@ -2223,8 +2223,7 @@ fn confirm_async_iterator_candidate<'cx, 'tcx>(
obligation: &ProjectionTyObligation<'tcx>, obligation: &ProjectionTyObligation<'tcx>,
nested: Vec<PredicateObligation<'tcx>>, nested: Vec<PredicateObligation<'tcx>>,
) -> Progress<'tcx> { ) -> Progress<'tcx> {
let ty::Coroutine(_, args, _) = let ty::Coroutine(_, args) = selcx.infcx.shallow_resolve(obligation.predicate.self_ty()).kind()
selcx.infcx.shallow_resolve(obligation.predicate.self_ty()).kind()
else { else {
unreachable!() unreachable!()
}; };

View file

@ -259,7 +259,7 @@ pub fn dtorck_constraint_for_ty_inner<'tcx>(
})? })?
} }
ty::Coroutine(_, args, _movability) => { ty::Coroutine(_, args) => {
// rust-lang/rust#49918: types can be constructed, stored // rust-lang/rust#49918: types can be constructed, stored
// in the interior, and sit idle when coroutine yields // in the interior, and sit idle when coroutine yields
// (and is subsequently dropped). // (and is subsequently dropped).

View file

@ -263,7 +263,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
candidates: &mut SelectionCandidateSet<'tcx>, candidates: &mut SelectionCandidateSet<'tcx>,
) { ) {
let self_ty = obligation.self_ty().skip_binder(); let self_ty = obligation.self_ty().skip_binder();
if let ty::Coroutine(did, args, _) = *self_ty.kind() { if let ty::Coroutine(did, args) = *self_ty.kind() {
// gen constructs get lowered to a special kind of coroutine that // gen constructs get lowered to a special kind of coroutine that
// should directly `impl AsyncIterator`. // should directly `impl AsyncIterator`.
if self.tcx().coroutine_is_async_gen(did) { if self.tcx().coroutine_is_async_gen(did) {
@ -486,7 +486,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
| ty::RawPtr(_) | ty::RawPtr(_)
| ty::Ref(_, _, _) | ty::Ref(_, _, _)
| ty::Closure(_, _) | ty::Closure(_, _)
| ty::Coroutine(_, _, _) | ty::Coroutine(_, _)
| ty::CoroutineWitness(..) | ty::CoroutineWitness(..)
| ty::Never | ty::Never
| ty::Tuple(_) | ty::Tuple(_)
@ -529,7 +529,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let def_id = obligation.predicate.def_id(); let def_id = obligation.predicate.def_id();
if self.tcx().trait_is_auto(def_id) { if self.tcx().trait_is_auto(def_id) {
match self_ty.kind() { match *self_ty.kind() {
ty::Dynamic(..) => { ty::Dynamic(..) => {
// For object types, we don't know what the closed // For object types, we don't know what the closed
// over types are. This means we conservatively // over types are. This means we conservatively
@ -564,10 +564,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// The auto impl might apply; we don't know. // The auto impl might apply; we don't know.
candidates.ambiguous = true; candidates.ambiguous = true;
} }
ty::Coroutine(_, _, movability) ty::Coroutine(coroutine_def_id, _)
if self.tcx().lang_items().unpin_trait() == Some(def_id) => if self.tcx().lang_items().unpin_trait() == Some(def_id) =>
{ {
match movability { match self.tcx().movability(coroutine_def_id) {
hir::Movability::Static => { hir::Movability::Static => {
// Immovable coroutines are never `Unpin`, so // Immovable coroutines are never `Unpin`, so
// suppress the normal auto-impl candidate for it. // suppress the normal auto-impl candidate for it.
@ -1023,7 +1023,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
| ty::FnPtr(_) | ty::FnPtr(_)
| ty::Dynamic(_, _, _) | ty::Dynamic(_, _, _)
| ty::Closure(_, _) | ty::Closure(_, _)
| ty::Coroutine(_, _, _) | ty::Coroutine(_, _)
| ty::CoroutineWitness(..) | ty::CoroutineWitness(..)
| ty::Never | ty::Never
| ty::Alias(..) | ty::Alias(..)

View file

@ -730,7 +730,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// touch bound regions, they just capture the in-scope // touch bound regions, they just capture the in-scope
// type/region parameters. // type/region parameters.
let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder()); let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder());
let ty::Coroutine(coroutine_def_id, args, _) = *self_ty.kind() else { let ty::Coroutine(coroutine_def_id, args) = *self_ty.kind() else {
bug!("closure candidate for non-closure {:?}", obligation); bug!("closure candidate for non-closure {:?}", obligation);
}; };
@ -768,7 +768,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// touch bound regions, they just capture the in-scope // touch bound regions, they just capture the in-scope
// type/region parameters. // type/region parameters.
let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder()); let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder());
let ty::Coroutine(coroutine_def_id, args, _) = *self_ty.kind() else { let ty::Coroutine(coroutine_def_id, args) = *self_ty.kind() else {
bug!("closure candidate for non-closure {:?}", obligation); bug!("closure candidate for non-closure {:?}", obligation);
}; };
@ -797,7 +797,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// touch bound regions, they just capture the in-scope // touch bound regions, they just capture the in-scope
// type/region parameters. // type/region parameters.
let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder()); let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder());
let ty::Coroutine(coroutine_def_id, args, _) = *self_ty.kind() else { let ty::Coroutine(coroutine_def_id, args) = *self_ty.kind() else {
bug!("closure candidate for non-closure {:?}", obligation); bug!("closure candidate for non-closure {:?}", obligation);
}; };
@ -826,7 +826,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// touch bound regions, they just capture the in-scope // touch bound regions, they just capture the in-scope
// type/region parameters. // type/region parameters.
let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder()); let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder());
let ty::Coroutine(coroutine_def_id, args, _) = *self_ty.kind() else { let ty::Coroutine(coroutine_def_id, args) = *self_ty.kind() else {
bug!("closure candidate for non-closure {:?}", obligation); bug!("closure candidate for non-closure {:?}", obligation);
}; };
@ -1298,7 +1298,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
ty::Closure(_, args) => { ty::Closure(_, args) => {
stack.push(args.as_closure().tupled_upvars_ty()); stack.push(args.as_closure().tupled_upvars_ty());
} }
ty::Coroutine(_, args, _) => { ty::Coroutine(_, args) => {
let coroutine = args.as_coroutine(); let coroutine = args.as_coroutine();
stack.extend([coroutine.tupled_upvars_ty(), coroutine.witness()]); stack.extend([coroutine.tupled_upvars_ty(), coroutine.witness()]);
} }

View file

@ -2176,7 +2176,6 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
ty::Dynamic(..) ty::Dynamic(..)
| ty::Str | ty::Str
| ty::Slice(..) | ty::Slice(..)
| ty::Coroutine(_, _, hir::Movability::Static)
| ty::Foreign(..) | ty::Foreign(..)
| ty::Ref(_, _, hir::Mutability::Mut) => None, | ty::Ref(_, _, hir::Mutability::Mut) => None,
@ -2185,26 +2184,31 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
Where(obligation.predicate.rebind(tys.iter().collect())) Where(obligation.predicate.rebind(tys.iter().collect()))
} }
ty::Coroutine(_, args, hir::Movability::Movable) => { ty::Coroutine(coroutine_def_id, args) => {
if self.tcx().features().coroutine_clone { match self.tcx().movability(coroutine_def_id) {
let resolved_upvars = hir::Movability::Static => None,
self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty()); hir::Movability::Movable => {
let resolved_witness = if self.tcx().features().coroutine_clone {
self.infcx.shallow_resolve(args.as_coroutine().witness()); let resolved_upvars =
if resolved_upvars.is_ty_var() || resolved_witness.is_ty_var() { self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty());
// Not yet resolved. let resolved_witness =
Ambiguous self.infcx.shallow_resolve(args.as_coroutine().witness());
} else { if resolved_upvars.is_ty_var() || resolved_witness.is_ty_var() {
let all = args // Not yet resolved.
.as_coroutine() Ambiguous
.upvar_tys() } else {
.iter() let all = args
.chain([args.as_coroutine().witness()]) .as_coroutine()
.collect::<Vec<_>>(); .upvar_tys()
Where(obligation.predicate.rebind(all)) .iter()
.chain([args.as_coroutine().witness()])
.collect::<Vec<_>>();
Where(obligation.predicate.rebind(all))
}
} else {
None
}
} }
} else {
None
} }
} }
@ -2307,7 +2311,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
t.rebind(vec![ty]) t.rebind(vec![ty])
} }
ty::Coroutine(_, args, _) => { ty::Coroutine(_, args) => {
let ty = self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty()); let ty = self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty());
let witness = args.as_coroutine().witness(); let witness = args.as_coroutine().witness();
t.rebind([ty].into_iter().chain(iter::once(witness)).collect()) t.rebind([ty].into_iter().chain(iter::once(witness)).collect())

View file

@ -97,7 +97,7 @@ fn fn_sig_for_fn_abi<'tcx>(
bound_vars, bound_vars,
) )
} }
ty::Coroutine(did, args, _) => { ty::Coroutine(did, args) => {
let coroutine_kind = tcx.coroutine_kind(did).unwrap(); let coroutine_kind = tcx.coroutine_kind(did).unwrap();
let sig = args.as_coroutine().sig(); let sig = args.as_coroutine().sig();

View file

@ -246,7 +246,7 @@ fn resolve_associated_item<'tcx>(
}) })
} }
} else if Some(trait_ref.def_id) == lang_items.future_trait() { } else if Some(trait_ref.def_id) == lang_items.future_trait() {
let ty::Coroutine(coroutine_def_id, args, _) = *rcvr_args.type_at(0).kind() else { let ty::Coroutine(coroutine_def_id, args) = *rcvr_args.type_at(0).kind() else {
bug!() bug!()
}; };
if Some(trait_item_id) == tcx.lang_items().future_poll_fn() { if Some(trait_item_id) == tcx.lang_items().future_poll_fn() {
@ -259,7 +259,7 @@ fn resolve_associated_item<'tcx>(
Some(Instance::new(trait_item_id, rcvr_args)) Some(Instance::new(trait_item_id, rcvr_args))
} }
} else if Some(trait_ref.def_id) == lang_items.iterator_trait() { } else if Some(trait_ref.def_id) == lang_items.iterator_trait() {
let ty::Coroutine(coroutine_def_id, args, _) = *rcvr_args.type_at(0).kind() else { let ty::Coroutine(coroutine_def_id, args) = *rcvr_args.type_at(0).kind() else {
bug!() bug!()
}; };
if Some(trait_item_id) == tcx.lang_items().next_fn() { if Some(trait_item_id) == tcx.lang_items().next_fn() {
@ -272,7 +272,7 @@ fn resolve_associated_item<'tcx>(
Some(Instance::new(trait_item_id, rcvr_args)) Some(Instance::new(trait_item_id, rcvr_args))
} }
} else if Some(trait_ref.def_id) == lang_items.async_iterator_trait() { } else if Some(trait_ref.def_id) == lang_items.async_iterator_trait() {
let ty::Coroutine(coroutine_def_id, args, _) = *rcvr_args.type_at(0).kind() else { let ty::Coroutine(coroutine_def_id, args) = *rcvr_args.type_at(0).kind() else {
bug!() bug!()
}; };
@ -287,7 +287,7 @@ fn resolve_associated_item<'tcx>(
// `AsyncIterator::poll_next` is generated by the compiler. // `AsyncIterator::poll_next` is generated by the compiler.
Some(Instance { def: ty::InstanceDef::Item(coroutine_def_id), args }) Some(Instance { def: ty::InstanceDef::Item(coroutine_def_id), args })
} else if Some(trait_ref.def_id) == lang_items.coroutine_trait() { } else if Some(trait_ref.def_id) == lang_items.coroutine_trait() {
let ty::Coroutine(coroutine_def_id, args, _) = *rcvr_args.type_at(0).kind() else { let ty::Coroutine(coroutine_def_id, args) = *rcvr_args.type_at(0).kind() else {
bug!() bug!()
}; };
if cfg!(debug_assertions) && tcx.item_name(trait_item_id) != sym::resume { if cfg!(debug_assertions) && tcx.item_name(trait_item_id) != sym::resume {

View file

@ -316,7 +316,7 @@ fn layout_of_uncached<'tcx>(
tcx.mk_layout(unit) tcx.mk_layout(unit)
} }
ty::Coroutine(def_id, args, _) => coroutine_layout(cx, ty, def_id, args)?, ty::Coroutine(def_id, args) => coroutine_layout(cx, ty, def_id, args)?,
ty::Closure(_, args) => { ty::Closure(_, args) => {
let tys = args.as_closure().upvar_tys(); let tys = args.as_closure().upvar_tys();
@ -961,7 +961,7 @@ fn record_layout_for_printing<'tcx>(cx: &LayoutCx<'tcx, TyCtxt<'tcx>>, layout: T
record(adt_kind.into(), adt_packed, opt_discr_size, variant_infos); record(adt_kind.into(), adt_packed, opt_discr_size, variant_infos);
} }
ty::Coroutine(def_id, args, _) => { ty::Coroutine(def_id, args) => {
debug!("print-type-size t: `{:?}` record coroutine", layout.ty); debug!("print-type-size t: `{:?}` record coroutine", layout.ty);
// Coroutines always have a begin/poisoned/end state with additional suspend points // Coroutines always have a begin/poisoned/end state with additional suspend points
let (variant_infos, opt_discr_size) = let (variant_infos, opt_discr_size) =

View file

@ -145,7 +145,7 @@ where
// for the coroutine witness and check whether any of the contained types // for the coroutine witness and check whether any of the contained types
// need to be dropped, and only require the captured types to be live // need to be dropped, and only require the captured types to be live
// if they do. // if they do.
ty::Coroutine(_, args, _) => { ty::Coroutine(_, args) => {
if self.reveal_coroutine_witnesses { if self.reveal_coroutine_witnesses {
queue_type(self, args.as_coroutine().witness()); queue_type(self, args.as_coroutine().witness());
} else { } else {

View file

@ -307,6 +307,16 @@ fn asyncness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Asyncness {
}) })
} }
fn movability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Movability {
let hir::Node::Expr(hir::Expr { kind: hir::ExprKind::Closure(closure), .. }) =
tcx.hir_node_by_def_id(def_id)
else {
bug!("expected query `movability` only called on coroutine def id");
};
closure.movability.expect("expected coroutine to have movability")
}
fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> BitSet<u32> { fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> BitSet<u32> {
let def = tcx.adt_def(def_id); let def = tcx.adt_def(def_id);
let num_params = tcx.generics_of(def_id).count(); let num_params = tcx.generics_of(def_id).count();
@ -354,6 +364,7 @@ fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> BitSet<u32
pub(crate) fn provide(providers: &mut Providers) { pub(crate) fn provide(providers: &mut Providers) {
*providers = Providers { *providers = Providers {
asyncness, asyncness,
movability,
adt_sized_constraint, adt_sized_constraint,
param_env, param_env,
param_env_reveal_all_normalized, param_env_reveal_all_normalized,

View file

@ -207,7 +207,7 @@ pub enum TyKind<I: Interner> {
/// ///
/// For more info about coroutine args, visit the documentation for /// For more info about coroutine args, visit the documentation for
/// `CoroutineArgs`. /// `CoroutineArgs`.
Coroutine(I::DefId, I::GenericArgs, Movability), Coroutine(I::DefId, I::GenericArgs),
/// A type representing the types stored inside a coroutine. /// A type representing the types stored inside a coroutine.
/// This should only appear as part of the `CoroutineArgs`. /// This should only appear as part of the `CoroutineArgs`.
@ -317,7 +317,7 @@ const fn tykind_discriminant<I: Interner>(value: &TyKind<I>) -> usize {
FnPtr(_) => 13, FnPtr(_) => 13,
Dynamic(..) => 14, Dynamic(..) => 14,
Closure(_, _) => 15, Closure(_, _) => 15,
Coroutine(_, _, _) => 16, Coroutine(_, _) => 16,
CoroutineWitness(_, _) => 17, CoroutineWitness(_, _) => 17,
Never => 18, Never => 18,
Tuple(_) => 19, Tuple(_) => 19,
@ -356,9 +356,7 @@ impl<I: Interner> PartialEq for TyKind<I> {
a_p == b_p && a_r == b_r && a_repr == b_repr a_p == b_p && a_r == b_r && a_repr == b_repr
} }
(Closure(a_d, a_s), Closure(b_d, b_s)) => a_d == b_d && a_s == b_s, (Closure(a_d, a_s), Closure(b_d, b_s)) => a_d == b_d && a_s == b_s,
(Coroutine(a_d, a_s, a_m), Coroutine(b_d, b_s, b_m)) => { (Coroutine(a_d, a_s), Coroutine(b_d, b_s)) => a_d == b_d && a_s == b_s,
a_d == b_d && a_s == b_s && a_m == b_m
}
(CoroutineWitness(a_d, a_s), CoroutineWitness(b_d, b_s)) => a_d == b_d && a_s == b_s, (CoroutineWitness(a_d, a_s), CoroutineWitness(b_d, b_s)) => a_d == b_d && a_s == b_s,
(Tuple(a_t), Tuple(b_t)) => a_t == b_t, (Tuple(a_t), Tuple(b_t)) => a_t == b_t,
(Alias(a_i, a_p), Alias(b_i, b_p)) => a_i == b_i && a_p == b_p, (Alias(a_i, a_p), Alias(b_i, b_p)) => a_i == b_i && a_p == b_p,
@ -432,9 +430,7 @@ impl<I: Interner> DebugWithInfcx<I> for TyKind<I> {
} }
}, },
Closure(d, s) => f.debug_tuple("Closure").field(d).field(&this.wrap(s)).finish(), Closure(d, s) => f.debug_tuple("Closure").field(d).field(&this.wrap(s)).finish(),
Coroutine(d, s, m) => { Coroutine(d, s) => f.debug_tuple("Coroutine").field(d).field(&this.wrap(s)).finish(),
f.debug_tuple("Coroutine").field(d).field(&this.wrap(s)).field(m).finish()
}
CoroutineWitness(d, s) => { CoroutineWitness(d, s) => {
f.debug_tuple("CoroutineWitness").field(d).field(&this.wrap(s)).finish() f.debug_tuple("CoroutineWitness").field(d).field(&this.wrap(s)).finish()
} }

View file

@ -1,7 +1,6 @@
use crate::mir::pretty::{function_body, pretty_statement, pretty_terminator}; use crate::mir::pretty::{function_body, pretty_statement, pretty_terminator};
use crate::ty::{ use crate::ty::{
AdtDef, ClosureDef, Const, CoroutineDef, GenericArgs, Movability, Region, RigidTy, Ty, TyKind, AdtDef, ClosureDef, Const, CoroutineDef, GenericArgs, Region, RigidTy, Ty, TyKind, VariantIdx,
VariantIdx,
}; };
use crate::{Error, Opaque, Span, Symbol}; use crate::{Error, Opaque, Span, Symbol};
use std::io; use std::io;
@ -646,9 +645,7 @@ impl Rvalue {
)), )),
AggregateKind::Adt(def, _, ref args, _, _) => Ok(def.ty_with_args(args)), AggregateKind::Adt(def, _, ref args, _, _) => Ok(def.ty_with_args(args)),
AggregateKind::Closure(def, ref args) => Ok(Ty::new_closure(def, args.clone())), AggregateKind::Closure(def, ref args) => Ok(Ty::new_closure(def, args.clone())),
AggregateKind::Coroutine(def, ref args, mov) => { AggregateKind::Coroutine(def, ref args) => Ok(Ty::new_coroutine(def, args.clone())),
Ok(Ty::new_coroutine(def, args.clone(), mov))
}
}, },
Rvalue::ShallowInitBox(_, ty) => Ok(Ty::new_box(*ty)), Rvalue::ShallowInitBox(_, ty) => Ok(Ty::new_box(*ty)),
Rvalue::CopyForDeref(place) => place.ty(locals), Rvalue::CopyForDeref(place) => place.ty(locals),
@ -662,7 +659,7 @@ pub enum AggregateKind {
Tuple, Tuple,
Adt(AdtDef, VariantIdx, GenericArgs, Option<UserTypeAnnotationIndex>, Option<FieldIdx>), Adt(AdtDef, VariantIdx, GenericArgs, Option<UserTypeAnnotationIndex>, Option<FieldIdx>),
Closure(ClosureDef, GenericArgs), Closure(ClosureDef, GenericArgs),
Coroutine(CoroutineDef, GenericArgs, Movability), Coroutine(CoroutineDef, GenericArgs),
} }
#[derive(Clone, Debug, Eq, PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]

View file

@ -443,7 +443,7 @@ pub fn pretty_ty(ty: TyKind) -> String {
RigidTy::FnDef(_, _) => format!("{:#?}", rigid_ty), RigidTy::FnDef(_, _) => format!("{:#?}", rigid_ty),
RigidTy::FnPtr(_) => format!("{:#?}", rigid_ty), RigidTy::FnPtr(_) => format!("{:#?}", rigid_ty),
RigidTy::Closure(_, _) => format!("{:#?}", rigid_ty), RigidTy::Closure(_, _) => format!("{:#?}", rigid_ty),
RigidTy::Coroutine(_, _, _) => format!("{:#?}", rigid_ty), RigidTy::Coroutine(_, _) => format!("{:#?}", rigid_ty),
RigidTy::Dynamic(data, region, repr) => { RigidTy::Dynamic(data, region, repr) => {
// FIXME: Fix binder printing, it looks ugly now // FIXME: Fix binder printing, it looks ugly now
pretty.push_str("("); pretty.push_str("(");

View file

@ -58,8 +58,8 @@ impl Ty {
} }
/// Create a new coroutine type. /// Create a new coroutine type.
pub fn new_coroutine(def: CoroutineDef, args: GenericArgs, mov: Movability) -> Ty { pub fn new_coroutine(def: CoroutineDef, args: GenericArgs) -> Ty {
Ty::from_rigid_kind(RigidTy::Coroutine(def, args, mov)) Ty::from_rigid_kind(RigidTy::Coroutine(def, args))
} }
/// Create a new box type that represents `Box<T>`, for the given inner type `T`. /// Create a new box type that represents `Box<T>`, for the given inner type `T`.
@ -460,7 +460,7 @@ pub enum RigidTy {
FnDef(FnDef, GenericArgs), FnDef(FnDef, GenericArgs),
FnPtr(PolyFnSig), FnPtr(PolyFnSig),
Closure(ClosureDef, GenericArgs), Closure(ClosureDef, GenericArgs),
Coroutine(CoroutineDef, GenericArgs, Movability), Coroutine(CoroutineDef, GenericArgs),
Dynamic(Vec<Binder<ExistentialPredicate>>, Region, DynKind), Dynamic(Vec<Binder<ExistentialPredicate>>, Region, DynKind),
Never, Never,
Tuple(Vec<Ty>), Tuple(Vec<Ty>),

View file

@ -148,7 +148,7 @@ impl Visitable for RigidTy {
RigidTy::FnDef(_, args) => args.visit(visitor), RigidTy::FnDef(_, args) => args.visit(visitor),
RigidTy::FnPtr(sig) => sig.visit(visitor), RigidTy::FnPtr(sig) => sig.visit(visitor),
RigidTy::Closure(_, args) => args.visit(visitor), RigidTy::Closure(_, args) => args.visit(visitor),
RigidTy::Coroutine(_, args, _) => args.visit(visitor), RigidTy::Coroutine(_, args) => args.visit(visitor),
RigidTy::CoroutineWitness(_, args) => args.visit(visitor), RigidTy::CoroutineWitness(_, args) => args.visit(visitor),
RigidTy::Dynamic(pred, r, _) => { RigidTy::Dynamic(pred, r, _) => {
pred.visit(visitor)?; pred.visit(visitor)?;

View file

@ -72,7 +72,7 @@ pub fn check(
&& let body = cx.tcx.hir().body(body_id) && let body = cx.tcx.hir().body(body_id)
&& let ret_ty = typeck.expr_ty(body.value) && let ret_ty = typeck.expr_ty(body.value)
&& implements_trait(cx, ret_ty, future, &[]) && implements_trait(cx, ret_ty, future, &[])
&& let ty::Coroutine(_, subs, _) = ret_ty.kind() && let ty::Coroutine(_, subs) = ret_ty.kind()
&& is_type_diagnostic_item(cx, subs.as_coroutine().return_ty(), sym::Result) && is_type_diagnostic_item(cx, subs.as_coroutine().return_ty(), sym::Result)
{ {
span_lint( span_lint(

View file

@ -11,7 +11,6 @@
CoroutineWitness(DefId(0:4 ~ async_await[ccf8]::a::{closure#0}), []), CoroutineWitness(DefId(0:4 ~ async_await[ccf8]::a::{closure#0}), []),
(), (),
], ],
Static,
), ),
source_info: SourceInfo { source_info: SourceInfo {
span: $DIR/async_await.rs:16:5: 16:14 (#9), span: $DIR/async_await.rs:16:5: 16:14 (#9),
@ -29,7 +28,6 @@
CoroutineWitness(DefId(0:4 ~ async_await[ccf8]::a::{closure#0}), []), CoroutineWitness(DefId(0:4 ~ async_await[ccf8]::a::{closure#0}), []),
(), (),
], ],
Static,
), ),
source_info: SourceInfo { source_info: SourceInfo {
span: $DIR/async_await.rs:17:5: 17:14 (#11), span: $DIR/async_await.rs:17:5: 17:14 (#11),