From bed388348bbb5df299c5b5bd08a39d9e556a53ad Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 13 Feb 2024 16:05:41 +0000 Subject: [PATCH] Format async bounds in rustfmt --- src/types.rs | 19 +++++++++++++++---- tests/target/asyncness.rs | 3 +++ 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 tests/target/asyncness.rs diff --git a/src/types.rs b/src/types.rs index cd2582e66be..f4ca18919db 100644 --- a/src/types.rs +++ b/src/types.rs @@ -537,18 +537,29 @@ fn rewrite(&self, context: &RewriteContext<'_>, _: Shape) -> Option { impl Rewrite for ast::GenericBound { fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { match *self { - ast::GenericBound::Trait(ref poly_trait_ref, modifiers) => { + ast::GenericBound::Trait( + ref poly_trait_ref, + ast::TraitBoundModifiers { + constness, + asyncness, + polarity, + }, + ) => { let snippet = context.snippet(self.span()); let has_paren = snippet.starts_with('(') && snippet.ends_with(')'); - let mut constness = modifiers.constness.as_str().to_string(); + let mut constness = constness.as_str().to_string(); if !constness.is_empty() { constness.push(' '); } - let polarity = modifiers.polarity.as_str(); + let mut asyncness = asyncness.as_str().to_string(); + if !asyncness.is_empty() { + asyncness.push(' '); + } + let polarity = polarity.as_str(); let shape = shape.offset_left(constness.len() + polarity.len())?; poly_trait_ref .rewrite(context, shape) - .map(|s| format!("{constness}{polarity}{s}")) + .map(|s| format!("{constness}{asyncness}{polarity}{s}")) .map(|s| if has_paren { format!("({})", s) } else { s }) } ast::GenericBound::Outlives(ref lifetime) => lifetime.rewrite(context, shape), diff --git a/tests/target/asyncness.rs b/tests/target/asyncness.rs new file mode 100644 index 00000000000..d91ac960499 --- /dev/null +++ b/tests/target/asyncness.rs @@ -0,0 +1,3 @@ +// rustfmt-edition: 2018 + +fn foo() -> impl async Fn() {}