about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeón Orell Valerian Liehr <me@fmease.dev>2023-12-20 15:22:06 +0100
committerLeón Orell Valerian Liehr <me@fmease.dev>2023-12-20 19:39:46 +0100
commit60419aa08a02fadac2e6496cf12c0bb568202ba5 (patch)
tree65e00e70ca0950cf9f64b8fb74e3a069a4eb938d
parentca2472edd727b4635eae725295f486d154ed337c (diff)
downloadrust-60419aa08a02fadac2e6496cf12c0bb568202ba5.tar.gz
rust-60419aa08a02fadac2e6496cf12c0bb568202ba5.zip
Refactor AST trait bound modifiers
-rw-r--r--src/types.rs31
1 files changed, 11 insertions, 20 deletions
diff --git a/src/types.rs b/src/types.rs
index a5a4244903c..cd2582e66be 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -537,28 +537,19 @@ 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, trait_bound_modifier) => {
+            ast::GenericBound::Trait(ref poly_trait_ref, modifiers) => {
                 let snippet = context.snippet(self.span());
                 let has_paren = snippet.starts_with('(') && snippet.ends_with(')');
-                let rewrite = match trait_bound_modifier {
-                    ast::TraitBoundModifier::None => poly_trait_ref.rewrite(context, shape),
-                    ast::TraitBoundModifier::Maybe => poly_trait_ref
-                        .rewrite(context, shape.offset_left(1)?)
-                        .map(|s| format!("?{}", s)),
-                    ast::TraitBoundModifier::MaybeConst(_) => poly_trait_ref
-                        .rewrite(context, shape.offset_left(7)?)
-                        .map(|s| format!("~const {}", s)),
-                    ast::TraitBoundModifier::MaybeConstMaybe => poly_trait_ref
-                        .rewrite(context, shape.offset_left(8)?)
-                        .map(|s| format!("~const ?{}", s)),
-                    ast::TraitBoundModifier::Negative => poly_trait_ref
-                        .rewrite(context, shape.offset_left(1)?)
-                        .map(|s| format!("!{}", s)),
-                    ast::TraitBoundModifier::MaybeConstNegative => poly_trait_ref
-                        .rewrite(context, shape.offset_left(8)?)
-                        .map(|s| format!("~const !{}", s)),
-                };
-                rewrite.map(|s| if has_paren { format!("({})", s) } else { s })
+                let mut constness = modifiers.constness.as_str().to_string();
+                if !constness.is_empty() {
+                    constness.push(' ');
+                }
+                let polarity = modifiers.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| if has_paren { format!("({})", s) } else { s })
             }
             ast::GenericBound::Outlives(ref lifetime) => lifetime.rewrite(context, shape),
         }