about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--tests/ui/traits/object/pretty.rs31
-rw-r--r--tests/ui/traits/object/pretty.stderr124
2 files changed, 155 insertions, 0 deletions
diff --git a/tests/ui/traits/object/pretty.rs b/tests/ui/traits/object/pretty.rs
new file mode 100644
index 00000000000..625c651d5f7
--- /dev/null
+++ b/tests/ui/traits/object/pretty.rs
@@ -0,0 +1,31 @@
+// Test for pretty-printing trait object types.
+
+trait Super {
+    type Assoc;
+}
+trait Any: Super {}
+trait Fixed: Super<Assoc = u8> {}
+trait FixedSub: Fixed {}
+
+trait SuperGeneric<'a> {
+    type Assoc;
+}
+trait AnyGeneric<'a>: SuperGeneric<'a> {}
+trait FixedGeneric1<'a>: SuperGeneric<'a, Assoc = &'a u8> {}
+trait FixedGeneric2<'a>: Super<Assoc = &'a u8> {}
+trait FixedHrtb: for<'a> SuperGeneric<'a, Assoc = &'a u8> {}
+
+fn dyn_super(x: &dyn Super<Assoc = u8>) { x } //~ERROR mismatched types
+fn dyn_any(x: &dyn Any<Assoc = u8>) { x } //~ERROR mismatched types
+fn dyn_fixed(x: &dyn Fixed) { x } //~ERROR mismatched types
+fn dyn_fixed_multi(x: &dyn Fixed<Assoc = u16>) { x } //~ERROR mismatched types
+fn dyn_fixed_sub(x: &dyn FixedSub) { x } //~ERROR mismatched types
+
+fn dyn_super_generic(x: &dyn for<'a> SuperGeneric<'a, Assoc = &'a u8>) { x } //~ERROR mismatched types
+fn dyn_any_generic(x: &dyn for<'a> AnyGeneric<'a, Assoc = &'a u8>) { x } //~ERROR mismatched types
+fn dyn_fixed_generic1(x: &dyn for<'a> FixedGeneric1<'a>) { x } //~ERROR mismatched types
+fn dyn_fixed_generic2(x: &dyn for<'a> FixedGeneric2<'a>) { x } //~ERROR mismatched types
+fn dyn_fixed_generic_multi(x: &dyn for<'a> FixedGeneric1<'a, Assoc = &u8>) { x } //~ERROR mismatched types
+fn dyn_fixed_hrtb(x: &dyn FixedHrtb) { x } //~ERROR mismatched types
+
+fn main() {}
diff --git a/tests/ui/traits/object/pretty.stderr b/tests/ui/traits/object/pretty.stderr
new file mode 100644
index 00000000000..2fa87e7a6fe
--- /dev/null
+++ b/tests/ui/traits/object/pretty.stderr
@@ -0,0 +1,124 @@
+error[E0308]: mismatched types
+  --> $DIR/pretty.rs:18:43
+   |
+LL | fn dyn_super(x: &dyn Super<Assoc = u8>) { x }
+   |                                        -  ^ expected `()`, found `&dyn Super<Assoc = u8>`
+   |                                        |
+   |                                        help: try adding a return type: `-> &dyn Super<Assoc = u8>`
+   |
+   = note: expected unit type `()`
+              found reference `&dyn Super<Assoc = u8>`
+
+error[E0308]: mismatched types
+  --> $DIR/pretty.rs:19:39
+   |
+LL | fn dyn_any(x: &dyn Any<Assoc = u8>) { x }
+   |                                    -  ^ expected `()`, found `&dyn Any<Assoc = u8>`
+   |                                    |
+   |                                    help: try adding a return type: `-> &dyn Any<Assoc = u8>`
+   |
+   = note: expected unit type `()`
+              found reference `&dyn Any<Assoc = u8>`
+
+error[E0308]: mismatched types
+  --> $DIR/pretty.rs:20:31
+   |
+LL | fn dyn_fixed(x: &dyn Fixed) { x }
+   |                            -  ^ expected `()`, found `&dyn Fixed<Assoc = u8>`
+   |                            |
+   |                            help: try adding a return type: `-> &dyn Fixed<Assoc = u8>`
+   |
+   = note: expected unit type `()`
+              found reference `&dyn Fixed<Assoc = u8>`
+
+error[E0308]: mismatched types
+  --> $DIR/pretty.rs:21:50
+   |
+LL | fn dyn_fixed_multi(x: &dyn Fixed<Assoc = u16>) { x }
+   |                                               -  ^ expected `()`, found `&dyn Fixed<Assoc = u16, Assoc = u8>`
+   |                                               |
+   |                                               help: try adding a return type: `-> &dyn Fixed<Assoc = u16, Assoc = u8>`
+   |
+   = note: expected unit type `()`
+              found reference `&dyn Fixed<Assoc = u16, Assoc = u8>`
+
+error[E0308]: mismatched types
+  --> $DIR/pretty.rs:22:38
+   |
+LL | fn dyn_fixed_sub(x: &dyn FixedSub) { x }
+   |                                   -  ^ expected `()`, found `&dyn FixedSub<Assoc = u8>`
+   |                                   |
+   |                                   help: try adding a return type: `-> &dyn FixedSub<Assoc = u8>`
+   |
+   = note: expected unit type `()`
+              found reference `&dyn FixedSub<Assoc = u8>`
+
+error[E0308]: mismatched types
+  --> $DIR/pretty.rs:24:74
+   |
+LL | fn dyn_super_generic(x: &dyn for<'a> SuperGeneric<'a, Assoc = &'a u8>) { x }
+   |                                                                       -  ^ expected `()`, found `&dyn SuperGeneric<'a, Assoc = &u8>`
+   |                                                                       |
+   |                                                                       help: try adding a return type: `-> &dyn for<'a> SuperGeneric<'a, for<'a> Assoc = &'a u8>`
+   |
+   = note: expected unit type `()`
+              found reference `&dyn for<'a> SuperGeneric<'a, for<'a> Assoc = &'a u8>`
+
+error[E0308]: mismatched types
+  --> $DIR/pretty.rs:25:70
+   |
+LL | fn dyn_any_generic(x: &dyn for<'a> AnyGeneric<'a, Assoc = &'a u8>) { x }
+   |                                                                   -  ^ expected `()`, found `&dyn AnyGeneric<'a, Assoc = &u8>`
+   |                                                                   |
+   |                                                                   help: try adding a return type: `-> &dyn for<'a> AnyGeneric<'a, for<'a> Assoc = &'a u8>`
+   |
+   = note: expected unit type `()`
+              found reference `&dyn for<'a> AnyGeneric<'a, for<'a> Assoc = &'a u8>`
+
+error[E0308]: mismatched types
+  --> $DIR/pretty.rs:26:60
+   |
+LL | fn dyn_fixed_generic1(x: &dyn for<'a> FixedGeneric1<'a>) { x }
+   |                                                         -  ^ expected `()`, found `&dyn FixedGeneric1<'a, Assoc = &u8>`
+   |                                                         |
+   |                                                         help: try adding a return type: `-> &dyn for<'a> FixedGeneric1<'a, for<'a> Assoc = &'a u8>`
+   |
+   = note: expected unit type `()`
+              found reference `&dyn for<'a> FixedGeneric1<'a, for<'a> Assoc = &'a u8>`
+
+error[E0308]: mismatched types
+  --> $DIR/pretty.rs:27:60
+   |
+LL | fn dyn_fixed_generic2(x: &dyn for<'a> FixedGeneric2<'a>) { x }
+   |                                                         -  ^ expected `()`, found `&dyn FixedGeneric2<'a, Assoc = &u8>`
+   |                                                         |
+   |                                                         help: try adding a return type: `-> &dyn for<'a> FixedGeneric2<'a, for<'a> Assoc = &'a u8>`
+   |
+   = note: expected unit type `()`
+              found reference `&dyn for<'a> FixedGeneric2<'a, for<'a> Assoc = &'a u8>`
+
+error[E0308]: mismatched types
+  --> $DIR/pretty.rs:28:78
+   |
+LL | fn dyn_fixed_generic_multi(x: &dyn for<'a> FixedGeneric1<'a, Assoc = &u8>) { x }
+   |                                                                           -  ^ expected `()`, found `&dyn FixedGeneric1<'a, Assoc = ..., Assoc = ...>`
+   |                                                                           |
+   |                                                                           help: try adding a return type: `-> &dyn for<'a> FixedGeneric1<'a, for<'a> Assoc = &u8, for<'a> Assoc = &'a u8>`
+   |
+   = note: expected unit type `()`
+              found reference `&dyn for<'a> FixedGeneric1<'a, for<'a> Assoc = &u8, for<'a> Assoc = &'a u8>`
+
+error[E0308]: mismatched types
+  --> $DIR/pretty.rs:29:40
+   |
+LL | fn dyn_fixed_hrtb(x: &dyn FixedHrtb) { x }
+   |                                     -  ^ expected `()`, found `&dyn FixedHrtb<Assoc = &u8>`
+   |                                     |
+   |                                     help: try adding a return type: `-> &dyn FixedHrtb<for<'a> Assoc = &'a u8>`
+   |
+   = note: expected unit type `()`
+              found reference `&dyn FixedHrtb<for<'a> Assoc = &'a u8>`
+
+error: aborting due to 11 previous errors
+
+For more information about this error, try `rustc --explain E0308`.