about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-04-26 22:37:36 +0000
committerMichael Goulet <michael@errs.io>2023-05-02 22:36:25 +0000
commit6fca051b76342f8c21ec85fb9a77103b7c05adb9 (patch)
tree131ad03e450681825c57fa283b214370f1a9cd7b /src
parent03469c3f2e5f7318b9dd47483f5656b321880408 (diff)
Rustfmt support for negative bounds, test
Diffstat (limited to 'src')
-rw-r--r--src/tools/rustfmt/src/types.rs8
-rw-r--r--src/tools/rustfmt/tests/target/negative-bounds.rs11
2 files changed, 17 insertions, 2 deletions
diff --git a/src/tools/rustfmt/src/types.rs b/src/tools/rustfmt/src/types.rs
index 9ebe38cc25f..f548388ed8b 100644
--- a/src/tools/rustfmt/src/types.rs
+++ b/src/tools/rustfmt/src/types.rs
@@ -552,8 +552,12 @@ impl Rewrite for ast::GenericBound {
                     ast::TraitBoundModifier::MaybeConstMaybe => poly_trait_ref
                         .rewrite(context, shape.offset_left(8)?)
                         .map(|s| format!("~const ?{}", s)),
-                    rustc_ast::TraitBoundModifier::Negative
-                    | rustc_ast::TraitBoundModifier::MaybeConstNegative => None,
+                    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 })
             }
diff --git a/src/tools/rustfmt/tests/target/negative-bounds.rs b/src/tools/rustfmt/tests/target/negative-bounds.rs
new file mode 100644
index 00000000000..4fb35cccf66
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/negative-bounds.rs
@@ -0,0 +1,11 @@
+fn negative()
+where
+    i32: !Copy,
+{
+}
+
+fn maybe_const_negative()
+where
+    i32: ~const !Copy,
+{
+}