about summary refs log tree commit diff
path: root/src/test/ui/trait-impl-bound-suggestions.rs
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2020-09-13 20:55:06 -0700
committeriximeow <me@iximeow.net>2020-09-13 21:24:34 -0700
commit0eac38b7a65c29734f4b2d34f35ee0aa9cb00a74 (patch)
treed2c46ff6ec5a1229f71f0b47e5824fa434d0e716 /src/test/ui/trait-impl-bound-suggestions.rs
parentdd33766e4a9a918058c3447d42491e874e21f7cc (diff)
downloadrust-0eac38b7a65c29734f4b2d34f35ee0aa9cb00a74.tar.gz
rust-0eac38b7a65c29734f4b2d34f35ee0aa9cb00a74.zip
fix syntax error in suggesting generic constraint in trait parameter
suggest `where T: Foo` for the first bound on a trait, then suggest
`, T: Foo` when the suggested bound would add to an existing set of
`where` clauses. `where T: Foo` may be the first bound if `T` has a
default, because we'd rather suggest
```
trait A<T=()> where T: Copy
```
than
```
trait A<T: Copy=()>
```
for legibility reasons.
Diffstat (limited to 'src/test/ui/trait-impl-bound-suggestions.rs')
-rw-r--r--src/test/ui/trait-impl-bound-suggestions.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/test/ui/trait-impl-bound-suggestions.rs b/src/test/ui/trait-impl-bound-suggestions.rs
new file mode 100644
index 00000000000..bf75175179e
--- /dev/null
+++ b/src/test/ui/trait-impl-bound-suggestions.rs
@@ -0,0 +1,20 @@
+// run-rustfix
+
+#[allow(unused)]
+use std::fmt::Debug;
+// Rustfix should add this, or use `std::fmt::Debug` instead.
+
+#[allow(dead_code)]
+struct ConstrainedStruct<X: Copy> {
+    x: X
+}
+
+#[allow(dead_code)]
+trait InsufficientlyConstrainedGeneric<X=()> {
+    fn return_the_constrained_type(&self, x: X) -> ConstrainedStruct<X> {
+        //~^ ERROR the trait bound `X: Copy` is not satisfied
+        ConstrainedStruct { x }
+    }
+}
+
+pub fn main() { }