merge DefKind::Coroutine into DefKind::Closure

This commit is contained in:
bohan 2023-11-26 21:05:08 +08:00
parent 274b5249eb
commit f23befe6c1
27 changed files with 83 additions and 94 deletions

View File

@ -89,7 +89,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
} }
} }
self.nodes.insert(hir_id.local_id, ParentedNode { parent: self.parent_node, node: node }); self.nodes.insert(hir_id.local_id, ParentedNode { parent: self.parent_node, node });
} }
fn with_parent<F: FnOnce(&mut Self)>(&mut self, parent_node_id: HirId, f: F) { fn with_parent<F: FnOnce(&mut Self)>(&mut self, parent_node_id: HirId, f: F) {

View File

@ -2072,8 +2072,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
.map(|name| format!("function `{name}`")) .map(|name| format!("function `{name}`"))
.unwrap_or_else(|| { .unwrap_or_else(|| {
match &self.infcx.tcx.def_kind(self.mir_def_id()) { match &self.infcx.tcx.def_kind(self.mir_def_id()) {
DefKind::Closure
if self
.infcx
.tcx
.is_coroutine(self.mir_def_id().to_def_id()) =>
{
"enclosing coroutine"
}
DefKind::Closure => "enclosing closure", DefKind::Closure => "enclosing closure",
DefKind::Coroutine => "enclosing coroutine",
kind => bug!("expected closure or coroutine, found {:?}", kind), kind => bug!("expected closure or coroutine, found {:?}", kind),
} }
.to_string() .to_string()

View File

@ -2678,8 +2678,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let typeck_root_args = ty::GenericArgs::identity_for_item(tcx, typeck_root_def_id); let typeck_root_args = ty::GenericArgs::identity_for_item(tcx, typeck_root_def_id);
let parent_args = match tcx.def_kind(def_id) { let parent_args = match tcx.def_kind(def_id) {
DefKind::Closure if tcx.is_coroutine(def_id.to_def_id()) => {
args.as_coroutine().parent_args()
}
DefKind::Closure => args.as_closure().parent_args(), DefKind::Closure => args.as_closure().parent_args(),
DefKind::Coroutine => args.as_coroutine().parent_args(),
DefKind::InlineConst => args.as_inline_const().parent_args(), DefKind::InlineConst => args.as_inline_const().parent_args(),
other => bug!("unexpected item {:?}", other), other => bug!("unexpected item {:?}", other),
}; };

View File

@ -373,10 +373,7 @@ fn add_unused_functions(cx: &CodegenCx<'_, '_>) {
// just "functions", like consts, statics, etc. Filter those out. // just "functions", like consts, statics, etc. Filter those out.
// If `ignore_unused_generics` was specified, filter out any // If `ignore_unused_generics` was specified, filter out any
// generic functions from consideration as well. // generic functions from consideration as well.
if !matches!( if !matches!(kind, DefKind::Fn | DefKind::AssocFn | DefKind::Closure) {
kind,
DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Coroutine
) {
return None; return None;
} }
if ignore_unused_generics && tcx.generics_of(def_id).requires_monomorphization(tcx) { if ignore_unused_generics && tcx.generics_of(def_id).requires_monomorphization(tcx) {

View File

@ -114,7 +114,6 @@ pub enum DefKind {
of_trait: bool, of_trait: bool,
}, },
Closure, Closure,
Coroutine,
} }
impl DefKind { impl DefKind {
@ -157,7 +156,6 @@ impl DefKind {
DefKind::Field => "field", DefKind::Field => "field",
DefKind::Impl { .. } => "implementation", DefKind::Impl { .. } => "implementation",
DefKind::Closure => "closure", DefKind::Closure => "closure",
DefKind::Coroutine => "coroutine",
DefKind::ExternCrate => "extern crate", DefKind::ExternCrate => "extern crate",
DefKind::GlobalAsm => "global assembly block", DefKind::GlobalAsm => "global assembly block",
} }
@ -216,7 +214,6 @@ impl DefKind {
| DefKind::LifetimeParam | DefKind::LifetimeParam
| DefKind::ExternCrate | DefKind::ExternCrate
| DefKind::Closure | DefKind::Closure
| DefKind::Coroutine
| DefKind::Use | DefKind::Use
| DefKind::ForeignMod | DefKind::ForeignMod
| DefKind::GlobalAsm | DefKind::GlobalAsm
@ -226,7 +223,7 @@ impl DefKind {
#[inline] #[inline]
pub fn is_fn_like(self) -> bool { pub fn is_fn_like(self) -> bool {
matches!(self, DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Coroutine) matches!(self, DefKind::Fn | DefKind::AssocFn | DefKind::Closure)
} }
/// Whether `query get_codegen_attrs` should be used with this definition. /// Whether `query get_codegen_attrs` should be used with this definition.
@ -236,7 +233,6 @@ impl DefKind {
| DefKind::AssocFn | DefKind::AssocFn
| DefKind::Ctor(..) | DefKind::Ctor(..)
| DefKind::Closure | DefKind::Closure
| DefKind::Coroutine
| DefKind::Static(_) => true, | DefKind::Static(_) => true,
DefKind::Mod DefKind::Mod
| DefKind::Struct | DefKind::Struct

View File

@ -1451,7 +1451,7 @@ fn opaque_type_cycle_error(
label_match(capture.place.ty(), capture.get_path_span(tcx)); label_match(capture.place.ty(), capture.get_path_span(tcx));
} }
// Label any coroutine locals that capture the opaque // Label any coroutine locals that capture the opaque
if let DefKind::Coroutine = tcx.def_kind(closure_def_id) if tcx.is_coroutine(closure_def_id)
&& let Some(coroutine_layout) = tcx.mir_coroutine_witnesses(closure_def_id) && let Some(coroutine_layout) = tcx.mir_coroutine_witnesses(closure_def_id)
{ {
for interior_ty in &coroutine_layout.field_tys { for interior_ty in &coroutine_layout.field_tys {
@ -1472,7 +1472,7 @@ pub(super) fn check_coroutine_obligations(
tcx: TyCtxt<'_>, tcx: TyCtxt<'_>,
def_id: LocalDefId, def_id: LocalDefId,
) -> Result<(), ErrorGuaranteed> { ) -> Result<(), ErrorGuaranteed> {
debug_assert!(matches!(tcx.def_kind(def_id), DefKind::Coroutine)); debug_assert!(tcx.is_coroutine(def_id.to_def_id()));
let typeck = tcx.typeck(def_id); let typeck = tcx.typeck(def_id);
let param_env = tcx.param_env(def_id); let param_env = tcx.param_env(def_id);

View File

@ -756,7 +756,7 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
}); });
tcx.hir().par_body_owners(|def_id| { tcx.hir().par_body_owners(|def_id| {
if let rustc_hir::def::DefKind::Coroutine = tcx.def_kind(def_id) { if tcx.is_coroutine(def_id.to_def_id()) {
tcx.ensure().mir_coroutine_witnesses(def_id); tcx.ensure().mir_coroutine_witnesses(def_id);
tcx.ensure().check_coroutine_obligations(def_id); tcx.ensure().check_coroutine_obligations(def_id);
} }

View File

@ -856,8 +856,7 @@ fn should_encode_span(def_kind: DefKind) -> bool {
| DefKind::OpaqueTy | DefKind::OpaqueTy
| DefKind::Field | DefKind::Field
| DefKind::Impl { .. } | DefKind::Impl { .. }
| DefKind::Closure | DefKind::Closure => true,
| DefKind::Coroutine => true,
DefKind::ForeignMod | DefKind::GlobalAsm => false, DefKind::ForeignMod | DefKind::GlobalAsm => false,
} }
} }
@ -897,8 +896,7 @@ fn should_encode_attrs(def_kind: DefKind) -> bool {
| DefKind::InlineConst | DefKind::InlineConst
| DefKind::OpaqueTy | DefKind::OpaqueTy
| DefKind::LifetimeParam | DefKind::LifetimeParam
| DefKind::GlobalAsm | DefKind::GlobalAsm => false,
| DefKind::Coroutine => false,
} }
} }
@ -933,8 +931,7 @@ fn should_encode_expn_that_defined(def_kind: DefKind) -> bool {
| DefKind::Field | DefKind::Field
| DefKind::LifetimeParam | DefKind::LifetimeParam
| DefKind::GlobalAsm | DefKind::GlobalAsm
| DefKind::Closure | DefKind::Closure => false,
| DefKind::Coroutine => false,
} }
} }
@ -969,7 +966,6 @@ fn should_encode_visibility(def_kind: DefKind) -> bool {
| DefKind::GlobalAsm | DefKind::GlobalAsm
| DefKind::Impl { .. } | DefKind::Impl { .. }
| DefKind::Closure | DefKind::Closure
| DefKind::Coroutine
| DefKind::ExternCrate => false, | DefKind::ExternCrate => false,
} }
} }
@ -1005,7 +1001,6 @@ fn should_encode_stability(def_kind: DefKind) -> bool {
| DefKind::InlineConst | DefKind::InlineConst
| DefKind::GlobalAsm | DefKind::GlobalAsm
| DefKind::Closure | DefKind::Closure
| DefKind::Coroutine
| DefKind::ExternCrate => false, | DefKind::ExternCrate => false,
} }
} }
@ -1048,6 +1043,8 @@ fn should_encode_mir(
| DefKind::AssocConst | DefKind::AssocConst
| DefKind::Static(..) | DefKind::Static(..)
| DefKind::Const => (true, false), | DefKind::Const => (true, false),
// Coroutines require optimized MIR to compute layout.
DefKind::Closure if tcx.is_coroutine(def_id.to_def_id()) => (false, true),
// Full-fledged functions + closures // Full-fledged functions + closures
DefKind::AssocFn | DefKind::Fn | DefKind::Closure => { DefKind::AssocFn | DefKind::Fn | DefKind::Closure => {
let generics = tcx.generics_of(def_id); let generics = tcx.generics_of(def_id);
@ -1061,8 +1058,6 @@ fn should_encode_mir(
|| tcx.is_const_default_method(def_id.to_def_id()); || tcx.is_const_default_method(def_id.to_def_id());
(is_const_fn, opt) (is_const_fn, opt)
} }
// Coroutines require optimized MIR to compute layout.
DefKind::Coroutine => (false, true),
// The others don't have MIR. // The others don't have MIR.
_ => (false, false), _ => (false, false),
} }
@ -1098,7 +1093,6 @@ fn should_encode_variances<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, def_kind: Def
| DefKind::InlineConst | DefKind::InlineConst
| DefKind::GlobalAsm | DefKind::GlobalAsm
| DefKind::Closure | DefKind::Closure
| DefKind::Coroutine
| DefKind::ExternCrate => false, | DefKind::ExternCrate => false,
DefKind::TyAlias => tcx.type_alias_is_lazy(def_id), DefKind::TyAlias => tcx.type_alias_is_lazy(def_id),
} }
@ -1127,8 +1121,7 @@ fn should_encode_generics(def_kind: DefKind) -> bool {
| DefKind::Impl { .. } | DefKind::Impl { .. }
| DefKind::Field | DefKind::Field
| DefKind::TyParam | DefKind::TyParam
| DefKind::Closure | DefKind::Closure => true,
| DefKind::Coroutine => true,
DefKind::Mod DefKind::Mod
| DefKind::ForeignMod | DefKind::ForeignMod
| DefKind::ConstParam | DefKind::ConstParam
@ -1157,7 +1150,6 @@ fn should_encode_type(tcx: TyCtxt<'_>, def_id: LocalDefId, def_kind: DefKind) ->
| DefKind::AssocFn | DefKind::AssocFn
| DefKind::AssocConst | DefKind::AssocConst
| DefKind::Closure | DefKind::Closure
| DefKind::Coroutine
| DefKind::ConstParam | DefKind::ConstParam
| DefKind::AnonConst | DefKind::AnonConst
| DefKind::InlineConst => true, | DefKind::InlineConst => true,
@ -1218,7 +1210,6 @@ fn should_encode_fn_sig(def_kind: DefKind) -> bool {
| DefKind::Impl { .. } | DefKind::Impl { .. }
| DefKind::AssocConst | DefKind::AssocConst
| DefKind::Closure | DefKind::Closure
| DefKind::Coroutine
| DefKind::ConstParam | DefKind::ConstParam
| DefKind::AnonConst | DefKind::AnonConst
| DefKind::InlineConst | DefKind::InlineConst
@ -1257,7 +1248,6 @@ fn should_encode_constness(def_kind: DefKind) -> bool {
| DefKind::OpaqueTy | DefKind::OpaqueTy
| DefKind::Impl { of_trait: false } | DefKind::Impl { of_trait: false }
| DefKind::ForeignTy | DefKind::ForeignTy
| DefKind::Coroutine
| DefKind::ConstParam | DefKind::ConstParam
| DefKind::InlineConst | DefKind::InlineConst
| DefKind::AssocTy | DefKind::AssocTy
@ -1292,7 +1282,6 @@ fn should_encode_const(def_kind: DefKind) -> bool {
| DefKind::Impl { .. } | DefKind::Impl { .. }
| DefKind::AssocFn | DefKind::AssocFn
| DefKind::Closure | DefKind::Closure
| DefKind::Coroutine
| DefKind::ConstParam | DefKind::ConstParam
| DefKind::AssocTy | DefKind::AssocTy
| DefKind::TyParam | DefKind::TyParam
@ -1452,8 +1441,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
self.encode_info_for_assoc_item(def_id); self.encode_info_for_assoc_item(def_id);
} }
} }
if let DefKind::Coroutine = def_kind { if def_kind == DefKind::Closure
let data = self.tcx.coroutine_kind(def_id).unwrap(); && let Some(data) = self.tcx.coroutine_kind(def_id)
{
record!(self.tables.coroutine_kind[def_id] <- data); record!(self.tables.coroutine_kind[def_id] <- data);
} }
if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind { if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind {
@ -1635,7 +1625,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
record!(self.tables.closure_saved_names_of_captured_variables[def_id.to_def_id()] record!(self.tables.closure_saved_names_of_captured_variables[def_id.to_def_id()]
<- tcx.closure_saved_names_of_captured_variables(def_id)); <- tcx.closure_saved_names_of_captured_variables(def_id));
if let DefKind::Coroutine = self.tcx.def_kind(def_id) if self.tcx.is_coroutine(def_id.to_def_id())
&& let Some(witnesses) = tcx.mir_coroutine_witnesses(def_id) && let Some(witnesses) = tcx.mir_coroutine_witnesses(def_id)
{ {
record!(self.tables.mir_coroutine_witnesses[def_id.to_def_id()] <- witnesses); record!(self.tables.mir_coroutine_witnesses[def_id.to_def_id()] <- witnesses);
@ -1662,7 +1652,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
} }
record!(self.tables.promoted_mir[def_id.to_def_id()] <- tcx.promoted_mir(def_id)); record!(self.tables.promoted_mir[def_id.to_def_id()] <- tcx.promoted_mir(def_id));
if let DefKind::Coroutine = self.tcx.def_kind(def_id) if self.tcx.is_coroutine(def_id.to_def_id())
&& let Some(witnesses) = tcx.mir_coroutine_witnesses(def_id) && let Some(witnesses) = tcx.mir_coroutine_witnesses(def_id)
{ {
record!(self.tables.mir_coroutine_witnesses[def_id.to_def_id()] <- witnesses); record!(self.tables.mir_coroutine_witnesses[def_id.to_def_id()] <- witnesses);

View File

@ -167,7 +167,6 @@ fixed_size_enum! {
( Impl { of_trait: false } ) ( Impl { of_trait: false } )
( Impl { of_trait: true } ) ( Impl { of_trait: true } )
( Closure ) ( Closure )
( Coroutine )
( Static(ast::Mutability::Not) ) ( Static(ast::Mutability::Not) )
( Static(ast::Mutability::Mut) ) ( Static(ast::Mutability::Mut) )
( Ctor(CtorOf::Struct, CtorKind::Fn) ) ( Ctor(CtorOf::Struct, CtorKind::Fn) )

View File

@ -236,8 +236,7 @@ impl<'hir> Map<'hir> {
Node::ConstBlock(_) => DefKind::InlineConst, Node::ConstBlock(_) => DefKind::InlineConst,
Node::Field(_) => DefKind::Field, Node::Field(_) => DefKind::Field,
Node::Expr(expr) => match expr.kind { Node::Expr(expr) => match expr.kind {
ExprKind::Closure(Closure { movability: None, .. }) => DefKind::Closure, ExprKind::Closure(_) => DefKind::Closure,
ExprKind::Closure(Closure { movability: Some(_), .. }) => DefKind::Coroutine,
_ => bug!("def_kind: unsupported node: {}", self.node_to_string(hir_id)), _ => bug!("def_kind: unsupported node: {}", self.node_to_string(hir_id)),
}, },
Node::GenericParam(param) => match param.kind { Node::GenericParam(param) => match param.kind {
@ -441,7 +440,7 @@ impl<'hir> Map<'hir> {
} }
DefKind::InlineConst => BodyOwnerKind::Const { inline: true }, DefKind::InlineConst => BodyOwnerKind::Const { inline: true },
DefKind::Ctor(..) | DefKind::Fn | DefKind::AssocFn => BodyOwnerKind::Fn, DefKind::Ctor(..) | DefKind::Fn | DefKind::AssocFn => BodyOwnerKind::Fn,
DefKind::Closure | DefKind::Coroutine => BodyOwnerKind::Closure, DefKind::Closure => BodyOwnerKind::Closure,
DefKind::Static(mt) => BodyOwnerKind::Static(mt), DefKind::Static(mt) => BodyOwnerKind::Static(mt),
dk => bug!("{:?} is not a body node: {:?}", def_id, dk), dk => bug!("{:?} is not a body node: {:?}", def_id, dk),
} }

View File

@ -800,6 +800,10 @@ impl<'tcx> TyCtxt<'tcx> {
self.diagnostic_items(did.krate).name_to_id.get(&name) == Some(&did) self.diagnostic_items(did.krate).name_to_id.get(&name) == Some(&did)
} }
pub fn is_coroutine(self, def_id: DefId) -> bool {
self.coroutine_kind(def_id).is_some()
}
/// Returns `true` if the node pointed to by `def_id` is a coroutine for an async construct. /// 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 { pub fn coroutine_is_async(self, def_id: DefId) -> bool {
matches!(self.coroutine_kind(def_id), Some(hir::CoroutineKind::Async(_))) matches!(self.coroutine_kind(def_id), Some(hir::CoroutineKind::Async(_)))

View File

@ -550,16 +550,13 @@ impl<'tcx> TyCtxt<'tcx> {
/// those are not yet phased out). The parent of the closure's /// those are not yet phased out). The parent of the closure's
/// `DefId` will also be the context where it appears. /// `DefId` will also be the context where it appears.
pub fn is_closure(self, def_id: DefId) -> bool { pub fn is_closure(self, def_id: DefId) -> bool {
matches!(self.def_kind(def_id), DefKind::Closure | DefKind::Coroutine) matches!(self.def_kind(def_id), DefKind::Closure)
} }
/// Returns `true` if `def_id` refers to a definition that does not have its own /// Returns `true` if `def_id` refers to a definition that does not have its own
/// type-checking context, i.e. closure, coroutine or inline const. /// type-checking context, i.e. closure, coroutine or inline const.
pub fn is_typeck_child(self, def_id: DefId) -> bool { pub fn is_typeck_child(self, def_id: DefId) -> bool {
matches!( matches!(self.def_kind(def_id), DefKind::Closure | DefKind::InlineConst)
self.def_kind(def_id),
DefKind::Closure | DefKind::Coroutine | DefKind::InlineConst
)
} }
/// Returns `true` if `def_id` refers to a trait (i.e., `trait Foo { ... }`). /// Returns `true` if `def_id` refers to a trait (i.e., `trait Foo { ... }`).
@ -732,11 +729,13 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn def_kind_descr(self, def_kind: DefKind, def_id: DefId) -> &'static str { pub fn def_kind_descr(self, def_kind: DefKind, def_id: DefId) -> &'static str {
match def_kind { match def_kind {
DefKind::AssocFn if self.associated_item(def_id).fn_has_self_parameter => "method", DefKind::AssocFn if self.associated_item(def_id).fn_has_self_parameter => "method",
DefKind::Coroutine => match self.coroutine_kind(def_id).unwrap() { DefKind::Closure if let Some(coroutine_kind) = self.coroutine_kind(def_id) => {
match coroutine_kind {
rustc_hir::CoroutineKind::Async(..) => "async closure", rustc_hir::CoroutineKind::Async(..) => "async closure",
rustc_hir::CoroutineKind::Coroutine => "coroutine", rustc_hir::CoroutineKind::Coroutine => "coroutine",
rustc_hir::CoroutineKind::Gen(..) => "gen closure", rustc_hir::CoroutineKind::Gen(..) => "gen closure",
}, }
}
_ => def_kind.descr(def_id), _ => def_kind.descr(def_id),
} }
} }
@ -750,11 +749,13 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn def_kind_descr_article(self, def_kind: DefKind, def_id: DefId) -> &'static str { pub fn def_kind_descr_article(self, def_kind: DefKind, def_id: DefId) -> &'static str {
match def_kind { match def_kind {
DefKind::AssocFn if self.associated_item(def_id).fn_has_self_parameter => "a", DefKind::AssocFn if self.associated_item(def_id).fn_has_self_parameter => "a",
DefKind::Coroutine => match self.coroutine_kind(def_id).unwrap() { DefKind::Closure if let Some(coroutine_kind) = self.coroutine_kind(def_id) => {
match coroutine_kind {
rustc_hir::CoroutineKind::Async(..) => "an", rustc_hir::CoroutineKind::Async(..) => "an",
rustc_hir::CoroutineKind::Coroutine => "a", rustc_hir::CoroutineKind::Coroutine => "a",
rustc_hir::CoroutineKind::Gen(..) => "a", rustc_hir::CoroutineKind::Gen(..) => "a",
}, }
}
_ => def_kind.article(), _ => def_kind.article(),
} }
} }

View File

@ -638,6 +638,14 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
); );
(sig.inputs().to_vec(), sig.output(), None) (sig.inputs().to_vec(), sig.output(), None)
} }
DefKind::Closure if coroutine_kind.is_some() => {
let coroutine_ty = tcx.type_of(def_id).instantiate_identity();
let ty::Coroutine(_, args, _) = coroutine_ty.kind() else { bug!() };
let args = args.as_coroutine();
let yield_ty = args.yield_ty();
let return_ty = args.return_ty();
(vec![coroutine_ty, args.resume_ty()], return_ty, Some(yield_ty))
}
DefKind::Closure => { DefKind::Closure => {
let closure_ty = tcx.type_of(def_id).instantiate_identity(); let closure_ty = tcx.type_of(def_id).instantiate_identity();
let ty::Closure(_, args) = closure_ty.kind() else { bug!() }; let ty::Closure(_, args) = closure_ty.kind() else { bug!() };
@ -650,14 +658,6 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) -
}; };
([self_ty].into_iter().chain(sig.inputs().to_vec()).collect(), sig.output(), None) ([self_ty].into_iter().chain(sig.inputs().to_vec()).collect(), sig.output(), None)
} }
DefKind::Coroutine => {
let coroutine_ty = tcx.type_of(def_id).instantiate_identity();
let ty::Coroutine(_, args, _) = coroutine_ty.kind() else { bug!() };
let args = args.as_coroutine();
let yield_ty = args.yield_ty();
let return_ty = args.return_ty();
(vec![coroutine_ty, args.resume_ty()], return_ty, Some(yield_ty))
}
dk => bug!("{:?} is not a body: {:?}", def_id, dk), dk => bug!("{:?} is not a body: {:?}", def_id, dk),
}; };

View File

@ -37,7 +37,7 @@ pub(crate) fn thir_body(
// The resume argument may be missing, in that case we need to provide it here. // The resume argument may be missing, in that case we need to provide it here.
// It will always be `()` in this case. // It will always be `()` in this case.
if tcx.def_kind(owner_def) == DefKind::Coroutine && body.params.is_empty() { if tcx.is_coroutine(owner_def.to_def_id()) && body.params.is_empty() {
cx.thir.params.push(Param { cx.thir.params.push(Param {
ty: Ty::new_unit(tcx), ty: Ty::new_unit(tcx),
pat: None, pat: None,
@ -119,6 +119,17 @@ impl<'tcx> Cx<'tcx> {
fn closure_env_param(&self, owner_def: LocalDefId, owner_id: HirId) -> Option<Param<'tcx>> { fn closure_env_param(&self, owner_def: LocalDefId, owner_id: HirId) -> Option<Param<'tcx>> {
match self.tcx.def_kind(owner_def) { match self.tcx.def_kind(owner_def) {
DefKind::Closure if self.tcx.is_coroutine(owner_def.to_def_id()) => {
let coroutine_ty = self.typeck_results.node_type(owner_id);
let coroutine_param = Param {
ty: coroutine_ty,
pat: None,
ty_span: None,
self_kind: None,
hir_id: None,
};
Some(coroutine_param)
}
DefKind::Closure => { DefKind::Closure => {
let closure_ty = self.typeck_results.node_type(owner_id); let closure_ty = self.typeck_results.node_type(owner_id);
@ -148,17 +159,6 @@ impl<'tcx> Cx<'tcx> {
Some(env_param) Some(env_param)
} }
DefKind::Coroutine => {
let coroutine_ty = self.typeck_results.node_type(owner_id);
let coroutine_param = Param {
ty: coroutine_ty,
pat: None,
ty_span: None,
self_kind: None,
hir_id: None,
};
Some(coroutine_param)
}
_ => None, _ => None,
} }
} }

View File

@ -84,8 +84,7 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
// FIXME(welseywiser) const prop doesn't work on coroutines because of query cycles // FIXME(welseywiser) const prop doesn't work on coroutines because of query cycles
// computing their layout. // computing their layout.
let is_coroutine = def_kind == DefKind::Coroutine; if tcx.is_coroutine(def_id.to_def_id()) {
if is_coroutine {
trace!("ConstProp skipped for coroutine {:?}", def_id); trace!("ConstProp skipped for coroutine {:?}", def_id);
return; return;
} }

View File

@ -61,7 +61,7 @@ impl<'tcx> MirLint<'tcx> for ConstPropLint {
// FIXME(welseywiser) const prop doesn't work on coroutines because of query cycles // FIXME(welseywiser) const prop doesn't work on coroutines because of query cycles
// computing their layout. // computing their layout.
if let DefKind::Coroutine = def_kind { if tcx.is_coroutine(def_id.to_def_id()) {
trace!("ConstPropLint skipped for coroutine {:?}", def_id); trace!("ConstPropLint skipped for coroutine {:?}", def_id);
return; return;
} }

View File

@ -395,7 +395,7 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: LocalDefId) -> Body<'_> {
/// mir borrowck *before* doing so in order to ensure that borrowck can be run and doesn't /// mir borrowck *before* doing so in order to ensure that borrowck can be run and doesn't
/// end up missing the source MIR due to stealing happening. /// end up missing the source MIR due to stealing happening.
fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &Steal<Body<'_>> { fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &Steal<Body<'_>> {
if let DefKind::Coroutine = tcx.def_kind(def) { if tcx.is_coroutine(def.to_def_id()) {
tcx.ensure_with_value().mir_coroutine_witnesses(def); tcx.ensure_with_value().mir_coroutine_witnesses(def);
} }
let mir_borrowck = tcx.mir_borrowck(def); let mir_borrowck = tcx.mir_borrowck(def);

View File

@ -131,7 +131,7 @@ fn mark_used_by_default_parameters<'tcx>(
unused_parameters: &mut UnusedGenericParams, unused_parameters: &mut UnusedGenericParams,
) { ) {
match tcx.def_kind(def_id) { match tcx.def_kind(def_id) {
DefKind::Closure | DefKind::Coroutine => { DefKind::Closure => {
for param in &generics.params { for param in &generics.params {
debug!(?param, "(closure/gen)"); debug!(?param, "(closure/gen)");
unused_parameters.mark_used(param.index); unused_parameters.mark_used(param.index);
@ -248,7 +248,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
fn visit_local_decl(&mut self, local: Local, local_decl: &LocalDecl<'tcx>) { fn visit_local_decl(&mut self, local: Local, local_decl: &LocalDecl<'tcx>) {
if local == Local::from_usize(1) { if local == Local::from_usize(1) {
let def_kind = self.tcx.def_kind(self.def_id); let def_kind = self.tcx.def_kind(self.def_id);
if matches!(def_kind, DefKind::Closure | DefKind::Coroutine) { if matches!(def_kind, DefKind::Closure) {
// Skip visiting the closure/coroutine that is currently being processed. This only // Skip visiting the closure/coroutine that is currently being processed. This only
// happens because the first argument to the closure is a reference to itself and // happens because the first argument to the closure is a reference to itself and
// that will call `visit_args`, resulting in each generic parameter captured being // that will call `visit_args`, resulting in each generic parameter captured being

View File

@ -653,8 +653,7 @@ impl<'tcx> EmbargoVisitor<'tcx> {
| DefKind::Field | DefKind::Field
| DefKind::GlobalAsm | DefKind::GlobalAsm
| DefKind::Impl { .. } | DefKind::Impl { .. }
| DefKind::Closure | DefKind::Closure => (),
| DefKind::Coroutine => (),
} }
} }
} }

View File

@ -973,8 +973,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
| DefKind::LifetimeParam | DefKind::LifetimeParam
| DefKind::GlobalAsm | DefKind::GlobalAsm
| DefKind::Closure | DefKind::Closure
| DefKind::Impl { .. } | DefKind::Impl { .. },
| DefKind::Coroutine,
_, _,
) )
| Res::Local(..) | Res::Local(..)

View File

@ -89,7 +89,7 @@ pub(crate) fn new_item_kind(kind: DefKind) -> ItemKind {
| DefKind::GlobalAsm => { | DefKind::GlobalAsm => {
unreachable!("Not a valid item kind: {kind:?}"); unreachable!("Not a valid item kind: {kind:?}");
} }
DefKind::Closure | DefKind::Coroutine | DefKind::AssocFn | DefKind::Fn => ItemKind::Fn, DefKind::Closure | DefKind::AssocFn | DefKind::Fn => ItemKind::Fn,
DefKind::Const | DefKind::InlineConst | DefKind::AssocConst | DefKind::AnonConst => { DefKind::Const | DefKind::InlineConst | DefKind::AssocConst | DefKind::AnonConst => {
ItemKind::Const ItemKind::Const
} }

View File

@ -234,7 +234,7 @@ fn compute_symbol_name<'tcx>(
// and we want to be sure to avoid any symbol conflicts here. // and we want to be sure to avoid any symbol conflicts here.
let is_globally_shared_function = matches!( let is_globally_shared_function = matches!(
tcx.def_kind(instance.def_id()), tcx.def_kind(instance.def_id()),
DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Coroutine | DefKind::Ctor(..) DefKind::Fn | DefKind::AssocFn | DefKind::Closure | DefKind::Ctor(..)
) && matches!( ) && matches!(
MonoItem::Fn(instance).instantiation_mode(tcx), MonoItem::Fn(instance).instantiation_mode(tcx),
InstantiationMode::GloballyShared { may_conflict: true } InstantiationMode::GloballyShared { may_conflict: true }

View File

@ -156,8 +156,7 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<'
| DefKind::Field | DefKind::Field
| DefKind::LifetimeParam | DefKind::LifetimeParam
| DefKind::GlobalAsm | DefKind::GlobalAsm
| DefKind::Closure | DefKind::Closure => ty::List::empty(),
| DefKind::Coroutine => ty::List::empty(),
} }
} }

View File

@ -313,7 +313,7 @@ fn opaque_types_defined_by<'tcx>(
| DefKind::Impl { .. } => {} | DefKind::Impl { .. } => {}
// Closures and coroutines are type checked with their parent, so we need to allow all // Closures and coroutines are type checked with their parent, so we need to allow all
// opaques from the closure signature *and* from the parent body. // opaques from the closure signature *and* from the parent body.
DefKind::Closure | DefKind::Coroutine | DefKind::InlineConst => { DefKind::Closure | DefKind::InlineConst => {
collector.opaques.extend(tcx.opaque_types_defined_by(tcx.local_parent(item))); collector.opaques.extend(tcx.opaque_types_defined_by(tcx.local_parent(item)));
} }
} }

View File

@ -67,7 +67,7 @@ pub(crate) fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
// These are not part of a public API, they can only appear as hidden types, and there // These are not part of a public API, they can only appear as hidden types, and there
// the interesting parts are solely in the signature of the containing item's opaque type // the interesting parts are solely in the signature of the containing item's opaque type
// or dyn type. // or dyn type.
DefKind::InlineConst | DefKind::Closure | DefKind::Coroutine => {} DefKind::InlineConst | DefKind::Closure => {}
DefKind::Impl { of_trait } => { DefKind::Impl { of_trait } => {
if of_trait { if of_trait {
let span = tcx.hir().get_by_def_id(item).expect_item().expect_impl().of_trait.unwrap().path.span; let span = tcx.hir().get_by_def_id(item).expect_item().expect_impl().of_trait.unwrap().path.span;

View File

@ -149,8 +149,7 @@ impl From<DefKind> for ItemType {
| DefKind::LifetimeParam | DefKind::LifetimeParam
| DefKind::GlobalAsm | DefKind::GlobalAsm
| DefKind::Impl { .. } | DefKind::Impl { .. }
| DefKind::Closure | DefKind::Closure => Self::ForeignType,
| DefKind::Coroutine => Self::ForeignType,
} }
} }
} }

View File

@ -1924,7 +1924,6 @@ fn resolution_failure(
Variant Variant
| Field | Field
| Closure | Closure
| Coroutine
| AssocTy | AssocTy
| AssocConst | AssocConst
| AssocFn | AssocFn