1
Fork 0

Rename CoroutineKind::Gen to ::Coroutine

This commit is contained in:
Oli Scherer 2023-10-20 09:02:22 +00:00
parent e96ce20b34
commit 2d91c76d5d
14 changed files with 29 additions and 25 deletions

View file

@ -712,7 +712,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let full_span = expr.span.to(await_kw_span); let full_span = expr.span.to(await_kw_span);
match self.coroutine_kind { match self.coroutine_kind {
Some(hir::CoroutineKind::Async(_)) => {} Some(hir::CoroutineKind::Async(_)) => {}
Some(hir::CoroutineKind::Gen) | None => { Some(hir::CoroutineKind::Coroutine) | None => {
self.tcx.sess.emit_err(AwaitOnlyInAsyncFnAndBlocks { self.tcx.sess.emit_err(AwaitOnlyInAsyncFnAndBlocks {
await_kw_span, await_kw_span,
item_span: self.current_item, item_span: self.current_item,
@ -930,7 +930,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
movability: Movability, movability: Movability,
) -> Option<hir::Movability> { ) -> Option<hir::Movability> {
match coroutine_kind { match coroutine_kind {
Some(hir::CoroutineKind::Gen) => { Some(hir::CoroutineKind::Coroutine) => {
if decl.inputs.len() > 1 { if decl.inputs.len() > 1 {
self.tcx.sess.emit_err(CoroutineTooManyParameters { fn_decl_span }); self.tcx.sess.emit_err(CoroutineTooManyParameters { fn_decl_span });
} }
@ -1445,11 +1445,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::ExprKind<'hir> { fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::ExprKind<'hir> {
match self.coroutine_kind { match self.coroutine_kind {
Some(hir::CoroutineKind::Gen) => {} Some(hir::CoroutineKind::Coroutine) => {}
Some(hir::CoroutineKind::Async(_)) => { Some(hir::CoroutineKind::Async(_)) => {
self.tcx.sess.emit_err(AsyncCoroutinesNotSupported { span }); self.tcx.sess.emit_err(AsyncCoroutinesNotSupported { span });
} }
None => self.coroutine_kind = Some(hir::CoroutineKind::Gen), None => self.coroutine_kind = Some(hir::CoroutineKind::Coroutine),
} }
let expr = let expr =

View file

@ -2488,7 +2488,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
AsyncCoroutineKind::Closure => "async closure", AsyncCoroutineKind::Closure => "async closure",
_ => bug!("async block/closure expected, but async function found."), _ => bug!("async block/closure expected, but async function found."),
}, },
CoroutineKind::Gen => "coroutine", CoroutineKind::Coroutine => "coroutine",
}, },
None => "closure", None => "closure",
}; };

View file

@ -698,7 +698,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
" of async function" " of async function"
} }
}, },
Some(hir::CoroutineKind::Gen) => " of coroutine", Some(hir::CoroutineKind::Coroutine) => " of coroutine",
None => " of closure", None => " of closure",
}; };
(span, mir_description, hir_ty) (span, mir_description, hir_ty)

View file

@ -563,7 +563,7 @@ fn coroutine_kind_label(coroutine_kind: Option<CoroutineKind>) -> &'static str {
Some(CoroutineKind::Async(AsyncCoroutineKind::Block)) => "async_block", Some(CoroutineKind::Async(AsyncCoroutineKind::Block)) => "async_block",
Some(CoroutineKind::Async(AsyncCoroutineKind::Closure)) => "async_closure", Some(CoroutineKind::Async(AsyncCoroutineKind::Closure)) => "async_closure",
Some(CoroutineKind::Async(AsyncCoroutineKind::Fn)) => "async_fn", Some(CoroutineKind::Async(AsyncCoroutineKind::Fn)) => "async_fn",
Some(CoroutineKind::Gen) => "coroutine", Some(CoroutineKind::Coroutine) => "coroutine",
None => "closure", None => "closure",
} }
} }

View file

@ -1043,7 +1043,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
TerminatorKind::InlineAsm { .. } => self.check_op(ops::InlineAsm), TerminatorKind::InlineAsm { .. } => self.check_op(ops::InlineAsm),
TerminatorKind::CoroutineDrop | TerminatorKind::Yield { .. } => { TerminatorKind::CoroutineDrop | TerminatorKind::Yield { .. } => {
self.check_op(ops::Coroutine(hir::CoroutineKind::Gen)) self.check_op(ops::Coroutine(hir::CoroutineKind::Coroutine))
} }
TerminatorKind::UnwindTerminate(_) => { TerminatorKind::UnwindTerminate(_) => {

View file

@ -1514,14 +1514,14 @@ pub enum CoroutineKind {
Async(AsyncCoroutineKind), Async(AsyncCoroutineKind),
/// A coroutine literal created via a `yield` inside a closure. /// A coroutine literal created via a `yield` inside a closure.
Gen, Coroutine,
} }
impl fmt::Display for CoroutineKind { impl fmt::Display for CoroutineKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
CoroutineKind::Async(k) => fmt::Display::fmt(k, f), CoroutineKind::Async(k) => fmt::Display::fmt(k, f),
CoroutineKind::Gen => f.write_str("coroutine"), CoroutineKind::Coroutine => f.write_str("coroutine"),
} }
} }
} }
@ -1530,7 +1530,7 @@ impl CoroutineKind {
pub fn descr(&self) -> &'static str { pub fn descr(&self) -> &'static str {
match self { match self {
CoroutineKind::Async(ask) => ask.descr(), CoroutineKind::Async(ask) => ask.descr(),
CoroutineKind::Gen => "coroutine", CoroutineKind::Coroutine => "coroutine",
} }
} }
} }
@ -2251,7 +2251,7 @@ impl From<CoroutineKind> for YieldSource {
fn from(kind: CoroutineKind) -> Self { fn from(kind: CoroutineKind) -> Self {
match kind { match kind {
// Guess based on the kind of the current coroutine. // Guess based on the kind of the current coroutine.
CoroutineKind::Gen => Self::Yield, CoroutineKind::Coroutine => Self::Yield,
CoroutineKind::Async(_) => Self::Await { expr: None }, CoroutineKind::Async(_) => Self::Await { expr: None },
} }
} }

View file

@ -58,7 +58,7 @@ pub(super) fn check_fn<'a, 'tcx>(
if let Some(kind) = body.coroutine_kind if let Some(kind) = body.coroutine_kind
&& can_be_coroutine.is_some() && can_be_coroutine.is_some()
{ {
let yield_ty = if kind == hir::CoroutineKind::Gen { let yield_ty = if kind == hir::CoroutineKind::Coroutine {
let yield_ty = fcx.next_ty_var(TypeVariableOrigin { let yield_ty = fcx.next_ty_var(TypeVariableOrigin {
kind: TypeVariableOriginKind::TypeInference, kind: TypeVariableOriginKind::TypeInference,
span, span,

View file

@ -139,9 +139,9 @@ impl<O> AssertKind<O> {
Overflow(op, _, _) => bug!("{:?} cannot overflow", op), Overflow(op, _, _) => bug!("{:?} cannot overflow", op),
DivisionByZero(_) => "attempt to divide by zero", DivisionByZero(_) => "attempt to divide by zero",
RemainderByZero(_) => "attempt to calculate the remainder with a divisor of zero", RemainderByZero(_) => "attempt to calculate the remainder with a divisor of zero",
ResumedAfterReturn(CoroutineKind::Gen) => "coroutine resumed after completion", ResumedAfterReturn(CoroutineKind::Coroutine) => "coroutine resumed after completion",
ResumedAfterReturn(CoroutineKind::Async(_)) => "`async fn` resumed after completion", ResumedAfterReturn(CoroutineKind::Async(_)) => "`async fn` resumed after completion",
ResumedAfterPanic(CoroutineKind::Gen) => "coroutine resumed after panicking", ResumedAfterPanic(CoroutineKind::Coroutine) => "coroutine resumed after panicking",
ResumedAfterPanic(CoroutineKind::Async(_)) => "`async fn` resumed after panicking", ResumedAfterPanic(CoroutineKind::Async(_)) => "`async fn` resumed after panicking",
BoundsCheck { .. } | MisalignedPointerDereference { .. } => { BoundsCheck { .. } | MisalignedPointerDereference { .. } => {
bug!("Unexpected AssertKind") bug!("Unexpected AssertKind")
@ -229,9 +229,13 @@ impl<O> AssertKind<O> {
DivisionByZero(_) => middle_assert_divide_by_zero, DivisionByZero(_) => middle_assert_divide_by_zero,
RemainderByZero(_) => middle_assert_remainder_by_zero, RemainderByZero(_) => middle_assert_remainder_by_zero,
ResumedAfterReturn(CoroutineKind::Async(_)) => middle_assert_async_resume_after_return, ResumedAfterReturn(CoroutineKind::Async(_)) => middle_assert_async_resume_after_return,
ResumedAfterReturn(CoroutineKind::Gen) => middle_assert_coroutine_resume_after_return, ResumedAfterReturn(CoroutineKind::Coroutine) => {
middle_assert_coroutine_resume_after_return
}
ResumedAfterPanic(CoroutineKind::Async(_)) => middle_assert_async_resume_after_panic, ResumedAfterPanic(CoroutineKind::Async(_)) => middle_assert_async_resume_after_panic,
ResumedAfterPanic(CoroutineKind::Gen) => middle_assert_coroutine_resume_after_panic, ResumedAfterPanic(CoroutineKind::Coroutine) => {
middle_assert_coroutine_resume_after_panic
}
MisalignedPointerDereference { .. } => middle_assert_misaligned_ptr_deref, MisalignedPointerDereference { .. } => middle_assert_misaligned_ptr_deref,
} }

View file

@ -788,7 +788,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
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 = let should_print_movability =
self.should_print_verbose() || coroutine_kind == hir::CoroutineKind::Gen; self.should_print_verbose() || coroutine_kind == hir::CoroutineKind::Coroutine;
if should_print_movability { if should_print_movability {
match movability { match movability {

View file

@ -748,7 +748,7 @@ impl<'tcx> TyCtxt<'tcx> {
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::Coroutine => match self.coroutine_kind(def_id).unwrap() {
rustc_hir::CoroutineKind::Async(..) => "async closure", rustc_hir::CoroutineKind::Async(..) => "async closure",
rustc_hir::CoroutineKind::Gen => "coroutine", rustc_hir::CoroutineKind::Coroutine => "coroutine",
}, },
_ => def_kind.descr(def_id), _ => def_kind.descr(def_id),
} }
@ -765,7 +765,7 @@ impl<'tcx> TyCtxt<'tcx> {
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::Coroutine => match self.coroutine_kind(def_id).unwrap() {
rustc_hir::CoroutineKind::Async(..) => "an", rustc_hir::CoroutineKind::Async(..) => "an",
rustc_hir::CoroutineKind::Gen => "a", rustc_hir::CoroutineKind::Coroutine => "a",
}, },
_ => def_kind.article(), _ => def_kind.article(),
} }

View file

@ -873,7 +873,7 @@ impl<'tcx> Stable<'tcx> for rustc_hir::CoroutineKind {
}; };
stable_mir::mir::CoroutineKind::Async(async_gen) stable_mir::mir::CoroutineKind::Async(async_gen)
} }
CoroutineKind::Gen => stable_mir::mir::CoroutineKind::Gen, CoroutineKind::Coroutine => stable_mir::mir::CoroutineKind::Coroutine,
} }
} }
} }

View file

@ -2409,7 +2409,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
let message = outer_coroutine let message = outer_coroutine
.and_then(|coroutine_did| { .and_then(|coroutine_did| {
Some(match self.tcx.coroutine_kind(coroutine_did).unwrap() { Some(match self.tcx.coroutine_kind(coroutine_did).unwrap() {
CoroutineKind::Gen => format!("coroutine is not {trait_name}"), CoroutineKind::Coroutine => format!("coroutine is not {trait_name}"),
CoroutineKind::Async(AsyncCoroutineKind::Fn) => self CoroutineKind::Async(AsyncCoroutineKind::Fn) => self
.tcx .tcx
.parent(coroutine_did) .parent(coroutine_did)
@ -2882,7 +2882,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
} }
ObligationCauseCode::SizedCoroutineInterior(coroutine_def_id) => { ObligationCauseCode::SizedCoroutineInterior(coroutine_def_id) => {
let what = match self.tcx.coroutine_kind(coroutine_def_id) { let what = match self.tcx.coroutine_kind(coroutine_def_id) {
None | Some(hir::CoroutineKind::Gen) => "yield", None | Some(hir::CoroutineKind::Coroutine) => "yield",
Some(hir::CoroutineKind::Async(..)) => "await", Some(hir::CoroutineKind::Async(..)) => "await",
}; };
err.note(format!( err.note(format!(

View file

@ -1615,7 +1615,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
fn describe_coroutine(&self, body_id: hir::BodyId) -> Option<&'static str> { fn describe_coroutine(&self, body_id: hir::BodyId) -> Option<&'static str> {
self.tcx.hir().body(body_id).coroutine_kind.map(|gen_kind| match gen_kind { self.tcx.hir().body(body_id).coroutine_kind.map(|gen_kind| match gen_kind {
hir::CoroutineKind::Gen => "a coroutine", hir::CoroutineKind::Coroutine => "a coroutine",
hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Block) => "an async block", hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Block) => "an async block",
hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Fn) => "an async function", hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Fn) => "an async function",
hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Closure) => "an async closure", hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Closure) => "an async closure",

View file

@ -134,7 +134,7 @@ pub enum UnOp {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum CoroutineKind { pub enum CoroutineKind {
Async(AsyncCoroutineKind), Async(AsyncCoroutineKind),
Gen, Coroutine,
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]