Option<CoroutineKind>

This commit is contained in:
Eric Holk 2023-11-30 16:39:56 -08:00
parent 97fdae1034
commit 13d284d177
3 changed files with 12 additions and 7 deletions

View File

@ -29,7 +29,7 @@ pub(crate) fn rewrite_closure(
binder: &ast::ClosureBinder, binder: &ast::ClosureBinder,
constness: ast::Const, constness: ast::Const,
capture: ast::CaptureBy, capture: ast::CaptureBy,
coro_kind: &ast::CoroutineKind, coro_kind: &Option<ast::CoroutineKind>,
movability: ast::Movability, movability: ast::Movability,
fn_decl: &ast::FnDecl, fn_decl: &ast::FnDecl,
body: &ast::Expr, body: &ast::Expr,
@ -233,7 +233,7 @@ fn rewrite_closure_fn_decl(
binder: &ast::ClosureBinder, binder: &ast::ClosureBinder,
constness: ast::Const, constness: ast::Const,
capture: ast::CaptureBy, capture: ast::CaptureBy,
coro_kind: &ast::CoroutineKind, coro_kind: &Option<ast::CoroutineKind>,
movability: ast::Movability, movability: ast::Movability,
fn_decl: &ast::FnDecl, fn_decl: &ast::FnDecl,
body: &ast::Expr, body: &ast::Expr,
@ -263,8 +263,13 @@ fn rewrite_closure_fn_decl(
} else { } else {
"" ""
}; };
let is_async = if coro_kind.is_async() { "async " } else { "" }; let (is_async, is_gen) = if let Some(coro_kind) = coro_kind {
let is_gen = if coro_kind.is_gen() { "gen " } else { "" }; let is_async = if coro_kind.is_async() { "async " } else { "" };
let is_gen = if coro_kind.is_gen() { "gen " } else { "" };
(is_async, is_gen)
} else {
("", "")
};
let mover = if matches!(capture, ast::CaptureBy::Value { .. }) { let mover = if matches!(capture, ast::CaptureBy::Value { .. }) {
"move " "move "
} else { } else {

View File

@ -287,7 +287,7 @@ pub(crate) struct FnSig<'a> {
decl: &'a ast::FnDecl, decl: &'a ast::FnDecl,
generics: &'a ast::Generics, generics: &'a ast::Generics,
ext: ast::Extern, ext: ast::Extern,
coro_kind: Cow<'a, ast::CoroutineKind>, coro_kind: Cow<'a, Option<ast::CoroutineKind>>,
constness: ast::Const, constness: ast::Const,
defaultness: ast::Defaultness, defaultness: ast::Defaultness,
unsafety: ast::Unsafe, unsafety: ast::Unsafe,
@ -343,7 +343,8 @@ fn to_str(&self, context: &RewriteContext<'_>) -> String {
result.push_str(&*format_visibility(context, self.visibility)); result.push_str(&*format_visibility(context, self.visibility));
result.push_str(format_defaultness(self.defaultness)); result.push_str(format_defaultness(self.defaultness));
result.push_str(format_constness(self.constness)); result.push_str(format_constness(self.constness));
result.push_str(format_coro(&self.coro_kind)); self.coro_kind
.map(|coro_kind| result.push_str(format_coro(&coro_kind)));
result.push_str(format_unsafety(self.unsafety)); result.push_str(format_unsafety(self.unsafety));
result.push_str(&format_extern( result.push_str(&format_extern(
self.ext, self.ext,

View File

@ -79,7 +79,6 @@ pub(crate) fn format_coro(coro_kind: &ast::CoroutineKind) -> &'static str {
match coro_kind { match coro_kind {
ast::CoroutineKind::Async { .. } => "async ", ast::CoroutineKind::Async { .. } => "async ",
ast::CoroutineKind::Gen { .. } => "gen ", ast::CoroutineKind::Gen { .. } => "gen ",
ast::CoroutineKind::None => "",
} }
} }