From 13d284d177fb48db15be929c8999e45d1b04802e Mon Sep 17 00:00:00 2001 From: Eric Holk Date: Thu, 30 Nov 2023 16:39:56 -0800 Subject: [PATCH] Option --- src/closures.rs | 13 +++++++++---- src/items.rs | 5 +++-- src/utils.rs | 1 - 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/closures.rs b/src/closures.rs index 23cd6e4c092..d79218e78ee 100644 --- a/src/closures.rs +++ b/src/closures.rs @@ -29,7 +29,7 @@ pub(crate) fn rewrite_closure( binder: &ast::ClosureBinder, constness: ast::Const, capture: ast::CaptureBy, - coro_kind: &ast::CoroutineKind, + coro_kind: &Option, movability: ast::Movability, fn_decl: &ast::FnDecl, body: &ast::Expr, @@ -233,7 +233,7 @@ fn rewrite_closure_fn_decl( binder: &ast::ClosureBinder, constness: ast::Const, capture: ast::CaptureBy, - coro_kind: &ast::CoroutineKind, + coro_kind: &Option, movability: ast::Movability, fn_decl: &ast::FnDecl, body: &ast::Expr, @@ -263,8 +263,13 @@ fn rewrite_closure_fn_decl( } else { "" }; - let is_async = if coro_kind.is_async() { "async " } else { "" }; - let is_gen = if coro_kind.is_gen() { "gen " } else { "" }; + let (is_async, is_gen) = if let Some(coro_kind) = coro_kind { + 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 { .. }) { "move " } else { diff --git a/src/items.rs b/src/items.rs index 0a1f823fe87..4dff65f8cd0 100644 --- a/src/items.rs +++ b/src/items.rs @@ -287,7 +287,7 @@ pub(crate) struct FnSig<'a> { decl: &'a ast::FnDecl, generics: &'a ast::Generics, ext: ast::Extern, - coro_kind: Cow<'a, ast::CoroutineKind>, + coro_kind: Cow<'a, Option>, constness: ast::Const, defaultness: ast::Defaultness, 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_defaultness(self.defaultness)); 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_extern( self.ext, diff --git a/src/utils.rs b/src/utils.rs index 18d8f0cdbd7..5805e417c04 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -79,7 +79,6 @@ pub(crate) fn format_coro(coro_kind: &ast::CoroutineKind) -> &'static str { match coro_kind { ast::CoroutineKind::Async { .. } => "async ", ast::CoroutineKind::Gen { .. } => "gen ", - ast::CoroutineKind::None => "", } }