diff options
| author | Eric Holk <ericholk@microsoft.com> | 2023-11-30 16:39:56 -0800 |
|---|---|---|
| committer | Eric Holk <ericholk@microsoft.com> | 2023-12-04 13:03:37 -0800 |
| commit | f9d1f922dcd335e534d40923ab54088c07a5403e (patch) | |
| tree | c268e5049e6492ebdbe081b049c562b51031d799 /src/tools/rustfmt | |
| parent | 48d5f1f0f26b78f76c5fcf0dda5ac93b8754aeb6 (diff) | |
| download | rust-f9d1f922dcd335e534d40923ab54088c07a5403e.tar.gz rust-f9d1f922dcd335e534d40923ab54088c07a5403e.zip | |
Option<CoroutineKind>
Diffstat (limited to 'src/tools/rustfmt')
| -rw-r--r-- | src/tools/rustfmt/src/closures.rs | 13 | ||||
| -rw-r--r-- | src/tools/rustfmt/src/items.rs | 5 | ||||
| -rw-r--r-- | src/tools/rustfmt/src/utils.rs | 1 |
3 files changed, 12 insertions, 7 deletions
diff --git a/src/tools/rustfmt/src/closures.rs b/src/tools/rustfmt/src/closures.rs index 23cd6e4c092..d79218e78ee 100644 --- a/src/tools/rustfmt/src/closures.rs +++ b/src/tools/rustfmt/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<ast::CoroutineKind>, 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<ast::CoroutineKind>, 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/tools/rustfmt/src/items.rs b/src/tools/rustfmt/src/items.rs index 0a1f823fe87..4dff65f8cd0 100644 --- a/src/tools/rustfmt/src/items.rs +++ b/src/tools/rustfmt/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<ast::CoroutineKind>>, constness: ast::Const, defaultness: ast::Defaultness, unsafety: ast::Unsafe, @@ -343,7 +343,8 @@ impl<'a> FnSig<'a> { 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/tools/rustfmt/src/utils.rs b/src/tools/rustfmt/src/utils.rs index 18d8f0cdbd7..5805e417c04 100644 --- a/src/tools/rustfmt/src/utils.rs +++ b/src/tools/rustfmt/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 => "", } } |
