about summary refs log tree commit diff
path: root/src/tools/rustfmt
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2024-02-14 15:41:27 +0100
committerGitHub <noreply@github.com>2024-02-14 15:41:27 +0100
commitdd4851b338730a5c1de536dcedd12bf515ff5856 (patch)
tree0321bcc0f7cf2f8b0cc7a184c3ec1b054caff4a2 /src/tools/rustfmt
parent8e690fdd6abc2c3ac534b6a589ec983c18f86c62 (diff)
parent73536ca730b96b784a6a70e2ef109adc493b2771 (diff)
downloadrust-dd4851b338730a5c1de536dcedd12bf515ff5856.tar.gz
rust-dd4851b338730a5c1de536dcedd12bf515ff5856.zip
Rollup merge of #121035 - compiler-errors:rustfmt-asyncness, r=calebcartwright
Format `async` trait bounds in rustfmt

r? `@ytmimi` or `@calebcartwright`

This PR opts to do formatting in the rust-lang/rust tree because otherwise we'd have to wait until a full sync, and rustfmt is currently totally removing the `async` keyword.

cc https://github.com/rust-lang/rustfmt/issues/6070
Diffstat (limited to 'src/tools/rustfmt')
-rw-r--r--src/tools/rustfmt/src/types.rs19
-rw-r--r--src/tools/rustfmt/tests/target/asyncness.rs3
2 files changed, 18 insertions, 4 deletions
diff --git a/src/tools/rustfmt/src/types.rs b/src/tools/rustfmt/src/types.rs
index aaef80f4aef..4cd8e6a703e 100644
--- a/src/tools/rustfmt/src/types.rs
+++ b/src/tools/rustfmt/src/types.rs
@@ -537,18 +537,29 @@ impl Rewrite for ast::Lifetime {
 impl Rewrite for ast::GenericBound {
     fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
         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/src/tools/rustfmt/tests/target/asyncness.rs b/src/tools/rustfmt/tests/target/asyncness.rs
new file mode 100644
index 00000000000..d91ac960499
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/asyncness.rs
@@ -0,0 +1,3 @@
+// rustfmt-edition: 2018
+
+fn foo() -> impl async Fn() {}