diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 222b975010699..495b255583c2a 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -275,7 +275,7 @@ fn do_mir_borrowck<'tcx>( if let Some(local) = body.local_decls.raw.get(1) // Get the interior types and args which typeck computed && let ty::Coroutine(def_id, _) = *local.ty.kind() - && tcx.movability(def_id) == hir::Movability::Movable + && tcx.coroutine_movability(def_id) == hir::Movability::Movable { true } else { diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 5e0bab516b3e9..bb8f4af8e97ae 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -240,7 +240,6 @@ provide! { tcx, def_id, other, cdata, mir_const_qualif => { table } rendered_const => { table } asyncness => { table_direct } - movability => { table_direct } fn_arg_names => { table } coroutine_kind => { table_direct } trait_def => { table } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index f3d5ec6c4270d..6d9cd5ecdc787 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1432,8 +1432,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { if def_kind == DefKind::Closure && let Some(coroutine_kind) = self.tcx.coroutine_kind(def_id) { - self.tables.coroutine_kind.set(def_id.index, Some(coroutine_kind)); - self.tables.movability.set(def_id.index, Some(self.tcx.movability(def_id))); + self.tables.coroutine_kind.set(def_id.index, Some(coroutine_kind)) } if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind { self.encode_info_for_adt(local_id); diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index f3493a329ab8b..d496e7494e7f8 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -447,7 +447,6 @@ define_tables! { mir_const_qualif: Table>, rendered_const: Table>, asyncness: Table, - movability: Table, fn_arg_names: Table>, coroutine_kind: Table, trait_def: Table>, diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index adef68feaaef9..8e7aaee065fd3 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -1308,7 +1308,7 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> { self.push("coroutine"); self.push(&format!("+ def_id: {def_id:?}")); self.push(&format!("+ args: {args:#?}")); - self.push(&format!("+ movability: {:?}", self.tcx.movability(def_id))); + self.push(&format!("+ kind: {:?}", self.tcx.coroutine_kind(def_id))); } AggregateKind::Adt(_, _, _, Some(user_ty), _) => { diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index add54a0a94eca..3a54f5f6b3d01 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -721,11 +721,6 @@ rustc_queries! { 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 /// actually sees it as const fn (e.g., the const-fn-ness might be unstable and you might /// not have the feature gate active). diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 17691de630f1d..5752c92f0aada 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -847,6 +847,10 @@ impl<'tcx> TyCtxt<'tcx> { self.coroutine_kind(def_id).is_some() } + pub fn coroutine_movability(self, def_id: DefId) -> hir::Movability { + self.coroutine_kind(def_id).expect("expected a coroutine").movability() + } + /// Returns `true` if the node pointed to by `def_id` is a coroutine for an async construct. pub fn coroutine_is_async(self, def_id: DefId) -> bool { matches!( diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index c1950a219c96a..99384e34222d9 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -790,7 +790,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { || matches!(coroutine_kind, hir::CoroutineKind::Coroutine(_)); if should_print_movability { - match self.tcx().movability(did) { + match coroutine_kind.movability() { hir::Movability::Movable => {} hir::Movability::Static => p!("static "), } diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index f5f0f20e3b12f..8ec70c58c4618 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -553,7 +553,7 @@ impl<'tcx> Cx<'tcx> { let (def_id, args, movability) = match *closure_ty.kind() { ty::Closure(def_id, args) => (def_id, UpvarArgs::Closure(args), None), ty::Coroutine(def_id, args) => { - (def_id, UpvarArgs::Coroutine(args), Some(tcx.movability(def_id))) + (def_id, UpvarArgs::Coroutine(args), Some(tcx.coroutine_movability(def_id))) } _ => { span_bug!(expr.span, "closure expr w/o closure type: {:?}", closure_ty); diff --git a/compiler/rustc_mir_transform/src/coroutine.rs b/compiler/rustc_mir_transform/src/coroutine.rs index 62fc15ee775e9..5e434d30b003b 100644 --- a/compiler/rustc_mir_transform/src/coroutine.rs +++ b/compiler/rustc_mir_transform/src/coroutine.rs @@ -1565,7 +1565,7 @@ pub(crate) fn mir_coroutine_witnesses<'tcx>( let coroutine_ty = body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty; let movable = match *coroutine_ty.kind() { - ty::Coroutine(def_id, _) => tcx.movability(def_id) == hir::Movability::Movable, + ty::Coroutine(def_id, _) => tcx.coroutine_movability(def_id) == hir::Movability::Movable, ty::Error(_) => return None, _ => span_bug!(body.span, "unexpected coroutine type {}", coroutine_ty), }; @@ -1597,12 +1597,13 @@ impl<'tcx> MirPass<'tcx> for StateTransform { // The first argument is the coroutine type passed by value let coroutine_ty = body.local_decls.raw[1].ty; + let coroutine_kind = body.coroutine_kind().unwrap(); // Get the discriminant type and args which typeck computed let (discr_ty, movable) = match *coroutine_ty.kind() { - ty::Coroutine(def_id, args) => { + ty::Coroutine(_, args) => { let args = args.as_coroutine(); - (args.discr_ty(tcx), tcx.movability(def_id) == hir::Movability::Movable) + (args.discr_ty(tcx), coroutine_kind.movability() == hir::Movability::Movable) } _ => { tcx.dcx().span_delayed_bug( @@ -1613,19 +1614,13 @@ impl<'tcx> MirPass<'tcx> for StateTransform { } }; - let is_async_kind = matches!( - body.coroutine_kind(), - Some(CoroutineKind::Desugared(CoroutineDesugaring::Async, _)) - ); - let is_async_gen_kind = matches!( - body.coroutine_kind(), - Some(CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, _)) - ); - let is_gen_kind = matches!( - body.coroutine_kind(), - Some(CoroutineKind::Desugared(CoroutineDesugaring::Gen, _)) - ); - let new_ret_ty = match body.coroutine_kind().unwrap() { + let is_async_kind = + matches!(coroutine_kind, CoroutineKind::Desugared(CoroutineDesugaring::Async, _)); + let is_async_gen_kind = + matches!(coroutine_kind, CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, _)); + let is_gen_kind = + matches!(coroutine_kind, CoroutineKind::Desugared(CoroutineDesugaring::Gen, _)); + let new_ret_ty = match coroutine_kind { CoroutineKind::Desugared(CoroutineDesugaring::Async, _) => { // Compute Poll let poll_did = tcx.require_lang_item(LangItem::Poll, None); diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index 983834ef19569..f6b820bfcd01f 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -395,7 +395,7 @@ fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) - 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::Coroutine(coroutine_def_id, args) => { - assert_eq!(tcx.movability(coroutine_def_id), hir::Movability::Movable); + assert_eq!(tcx.coroutine_movability(*coroutine_def_id), hir::Movability::Movable); 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), diff --git a/compiler/rustc_smir/src/rustc_smir/convert/mir.rs b/compiler/rustc_smir/src/rustc_smir/convert/mir.rs index 027fdb3493b9c..c5fb6f7a26f18 100644 --- a/compiler/rustc_smir/src/rustc_smir/convert/mir.rs +++ b/compiler/rustc_smir/src/rustc_smir/convert/mir.rs @@ -535,7 +535,7 @@ impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> { stable_mir::mir::AggregateKind::Coroutine( tables.coroutine_def(*def_id), generic_arg.stable(tables), - tables.tcx.movability(*def_id).stable(tables), + tables.tcx.coroutine_movability(*def_id).stable(tables), ) } } diff --git a/compiler/rustc_smir/src/rustc_smir/convert/ty.rs b/compiler/rustc_smir/src/rustc_smir/convert/ty.rs index b12951859bcca..f0f1d798d44b4 100644 --- a/compiler/rustc_smir/src/rustc_smir/convert/ty.rs +++ b/compiler/rustc_smir/src/rustc_smir/convert/ty.rs @@ -389,7 +389,7 @@ impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> { ty::Coroutine(def_id, generic_args) => TyKind::RigidTy(RigidTy::Coroutine( tables.coroutine_def(*def_id), generic_args.stable(tables), - tables.tcx.movability(*def_id).stable(tables), + tables.tcx.coroutine_movability(*def_id).stable(tables), )), ty::Never => TyKind::RigidTy(RigidTy::Never), ty::Tuple(fields) => { diff --git a/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs b/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs index 4bf905051664b..274a75a125c58 100644 --- a/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs +++ b/compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs @@ -193,7 +193,7 @@ 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::Coroutine(def_id, args) => match ecx.tcx().movability(def_id) { + ty::Coroutine(def_id, args) => match ecx.tcx().coroutine_movability(def_id) { Movability::Static => Err(NoSolution), Movability::Movable => { if ecx.tcx().features().coroutine_clone { diff --git a/compiler/rustc_trait_selection/src/solve/trait_goals.rs b/compiler/rustc_trait_selection/src/solve/trait_goals.rs index 00ceb44dd2e48..be07927568446 100644 --- a/compiler/rustc_trait_selection/src/solve/trait_goals.rs +++ b/compiler/rustc_trait_selection/src/solve/trait_goals.rs @@ -930,7 +930,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { ty::Coroutine(def_id, _) if Some(goal.predicate.def_id()) == self.tcx().lang_items().unpin_trait() => { - match self.tcx().movability(def_id) { + match self.tcx().coroutine_movability(def_id) { Movability::Static => Some(Err(NoSolution)), Movability::Movable => { Some(self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)) diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 7b74c02d2c630..54b91ab1d4d81 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -567,7 +567,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ty::Coroutine(coroutine_def_id, _) if self.tcx().lang_items().unpin_trait() == Some(def_id) => { - match self.tcx().movability(coroutine_def_id) { + match self.tcx().coroutine_movability(coroutine_def_id) { hir::Movability::Static => { // Immovable coroutines are never `Unpin`, so // suppress the normal auto-impl candidate for it. diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 2536a3d6ea505..c45925295ee72 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2185,7 +2185,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { } ty::Coroutine(coroutine_def_id, args) => { - match self.tcx().movability(coroutine_def_id) { + match self.tcx().coroutine_movability(coroutine_def_id) { hir::Movability::Static => None, hir::Movability::Movable => { if self.tcx().features().coroutine_clone { diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index 9cd750a6a3137..2158aacab03d8 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -307,16 +307,6 @@ 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 { let def = tcx.adt_def(def_id); let num_params = tcx.generics_of(def_id).count(); @@ -364,7 +354,6 @@ fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> BitSet