merge DefKind::Coroutine
into DefKind::Closure
This commit is contained in:
parent
274b5249eb
commit
f23befe6c1
27 changed files with 83 additions and 94 deletions
|
@ -236,8 +236,7 @@ impl<'hir> Map<'hir> {
|
|||
Node::ConstBlock(_) => DefKind::InlineConst,
|
||||
Node::Field(_) => DefKind::Field,
|
||||
Node::Expr(expr) => match expr.kind {
|
||||
ExprKind::Closure(Closure { movability: None, .. }) => DefKind::Closure,
|
||||
ExprKind::Closure(Closure { movability: Some(_), .. }) => DefKind::Coroutine,
|
||||
ExprKind::Closure(_) => DefKind::Closure,
|
||||
_ => bug!("def_kind: unsupported node: {}", self.node_to_string(hir_id)),
|
||||
},
|
||||
Node::GenericParam(param) => match param.kind {
|
||||
|
@ -441,7 +440,7 @@ impl<'hir> Map<'hir> {
|
|||
}
|
||||
DefKind::InlineConst => BodyOwnerKind::Const { inline: true },
|
||||
DefKind::Ctor(..) | DefKind::Fn | DefKind::AssocFn => BodyOwnerKind::Fn,
|
||||
DefKind::Closure | DefKind::Coroutine => BodyOwnerKind::Closure,
|
||||
DefKind::Closure => BodyOwnerKind::Closure,
|
||||
DefKind::Static(mt) => BodyOwnerKind::Static(mt),
|
||||
dk => bug!("{:?} is not a body node: {:?}", def_id, dk),
|
||||
}
|
||||
|
|
|
@ -800,6 +800,10 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
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.
|
||||
pub fn coroutine_is_async(self, def_id: DefId) -> bool {
|
||||
matches!(self.coroutine_kind(def_id), Some(hir::CoroutineKind::Async(_)))
|
||||
|
|
|
@ -550,16 +550,13 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
/// those are not yet phased out). The parent of the closure's
|
||||
/// `DefId` will also be the context where it appears.
|
||||
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
|
||||
/// type-checking context, i.e. closure, coroutine or inline const.
|
||||
pub fn is_typeck_child(self, def_id: DefId) -> bool {
|
||||
matches!(
|
||||
self.def_kind(def_id),
|
||||
DefKind::Closure | DefKind::Coroutine | DefKind::InlineConst
|
||||
)
|
||||
matches!(self.def_kind(def_id), DefKind::Closure | DefKind::InlineConst)
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
match def_kind {
|
||||
DefKind::AssocFn if self.associated_item(def_id).fn_has_self_parameter => "method",
|
||||
DefKind::Coroutine => match self.coroutine_kind(def_id).unwrap() {
|
||||
rustc_hir::CoroutineKind::Async(..) => "async closure",
|
||||
rustc_hir::CoroutineKind::Coroutine => "coroutine",
|
||||
rustc_hir::CoroutineKind::Gen(..) => "gen closure",
|
||||
},
|
||||
DefKind::Closure if let Some(coroutine_kind) = self.coroutine_kind(def_id) => {
|
||||
match coroutine_kind {
|
||||
rustc_hir::CoroutineKind::Async(..) => "async closure",
|
||||
rustc_hir::CoroutineKind::Coroutine => "coroutine",
|
||||
rustc_hir::CoroutineKind::Gen(..) => "gen closure",
|
||||
}
|
||||
}
|
||||
_ => 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 {
|
||||
match def_kind {
|
||||
DefKind::AssocFn if self.associated_item(def_id).fn_has_self_parameter => "a",
|
||||
DefKind::Coroutine => match self.coroutine_kind(def_id).unwrap() {
|
||||
rustc_hir::CoroutineKind::Async(..) => "an",
|
||||
rustc_hir::CoroutineKind::Coroutine => "a",
|
||||
rustc_hir::CoroutineKind::Gen(..) => "a",
|
||||
},
|
||||
DefKind::Closure if let Some(coroutine_kind) = self.coroutine_kind(def_id) => {
|
||||
match coroutine_kind {
|
||||
rustc_hir::CoroutineKind::Async(..) => "an",
|
||||
rustc_hir::CoroutineKind::Coroutine => "a",
|
||||
rustc_hir::CoroutineKind::Gen(..) => "a",
|
||||
}
|
||||
}
|
||||
_ => def_kind.article(),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue