Skip to content

Commit fd92021

Browse files
author
Lukas Markeffsky
committed
add test for pretty printing trait objects
1 parent d4f6f9e commit fd92021

File tree

2 files changed

+155
-0
lines changed

2 files changed

+155
-0
lines changed

tests/ui/traits/object/pretty.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Test for pretty-printing trait object types.
2+
3+
trait Super {
4+
type Assoc;
5+
}
6+
trait Any: Super {}
7+
trait Fixed: Super<Assoc = u8> {}
8+
trait FixedSub: Fixed {}
9+
10+
trait SuperGeneric<'a> {
11+
type Assoc;
12+
}
13+
trait AnyGeneric<'a>: SuperGeneric<'a> {}
14+
trait FixedGeneric1<'a>: SuperGeneric<'a, Assoc = &'a u8> {}
15+
trait FixedGeneric2<'a>: Super<Assoc = &'a u8> {}
16+
trait FixedHrtb: for<'a> SuperGeneric<'a, Assoc = &'a u8> {}
17+
18+
fn dyn_super(x: &dyn Super<Assoc = u8>) { x } //~ERROR mismatched types
19+
fn dyn_any(x: &dyn Any<Assoc = u8>) { x } //~ERROR mismatched types
20+
fn dyn_fixed(x: &dyn Fixed) { x } //~ERROR mismatched types
21+
fn dyn_fixed_multi(x: &dyn Fixed<Assoc = u16>) { x } //~ERROR mismatched types
22+
fn dyn_fixed_sub(x: &dyn FixedSub) { x } //~ERROR mismatched types
23+
24+
fn dyn_super_generic(x: &dyn for<'a> SuperGeneric<'a, Assoc = &'a u8>) { x } //~ERROR mismatched types
25+
fn dyn_any_generic(x: &dyn for<'a> AnyGeneric<'a, Assoc = &'a u8>) { x } //~ERROR mismatched types
26+
fn dyn_fixed_generic1(x: &dyn for<'a> FixedGeneric1<'a>) { x } //~ERROR mismatched types
27+
fn dyn_fixed_generic2(x: &dyn for<'a> FixedGeneric2<'a>) { x } //~ERROR mismatched types
28+
fn dyn_fixed_generic_multi(x: &dyn for<'a> FixedGeneric1<'a, Assoc = &u8>) { x } //~ERROR mismatched types
29+
fn dyn_fixed_hrtb(x: &dyn FixedHrtb) { x } //~ERROR mismatched types
30+
31+
fn main() {}

tests/ui/traits/object/pretty.stderr

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/pretty.rs:18:43
3+
|
4+
LL | fn dyn_super(x: &dyn Super<Assoc = u8>) { x }
5+
| - ^ expected `()`, found `&dyn Super<Assoc = u8>`
6+
| |
7+
| help: try adding a return type: `-> &dyn Super<Assoc = u8>`
8+
|
9+
= note: expected unit type `()`
10+
found reference `&dyn Super<Assoc = u8>`
11+
12+
error[E0308]: mismatched types
13+
--> $DIR/pretty.rs:19:39
14+
|
15+
LL | fn dyn_any(x: &dyn Any<Assoc = u8>) { x }
16+
| - ^ expected `()`, found `&dyn Any<Assoc = u8>`
17+
| |
18+
| help: try adding a return type: `-> &dyn Any<Assoc = u8>`
19+
|
20+
= note: expected unit type `()`
21+
found reference `&dyn Any<Assoc = u8>`
22+
23+
error[E0308]: mismatched types
24+
--> $DIR/pretty.rs:20:31
25+
|
26+
LL | fn dyn_fixed(x: &dyn Fixed) { x }
27+
| - ^ expected `()`, found `&dyn Fixed<Assoc = u8>`
28+
| |
29+
| help: try adding a return type: `-> &dyn Fixed<Assoc = u8>`
30+
|
31+
= note: expected unit type `()`
32+
found reference `&dyn Fixed<Assoc = u8>`
33+
34+
error[E0308]: mismatched types
35+
--> $DIR/pretty.rs:21:50
36+
|
37+
LL | fn dyn_fixed_multi(x: &dyn Fixed<Assoc = u16>) { x }
38+
| - ^ expected `()`, found `&dyn Fixed<Assoc = u16, Assoc = u8>`
39+
| |
40+
| help: try adding a return type: `-> &dyn Fixed<Assoc = u16, Assoc = u8>`
41+
|
42+
= note: expected unit type `()`
43+
found reference `&dyn Fixed<Assoc = u16, Assoc = u8>`
44+
45+
error[E0308]: mismatched types
46+
--> $DIR/pretty.rs:22:38
47+
|
48+
LL | fn dyn_fixed_sub(x: &dyn FixedSub) { x }
49+
| - ^ expected `()`, found `&dyn FixedSub<Assoc = u8>`
50+
| |
51+
| help: try adding a return type: `-> &dyn FixedSub<Assoc = u8>`
52+
|
53+
= note: expected unit type `()`
54+
found reference `&dyn FixedSub<Assoc = u8>`
55+
56+
error[E0308]: mismatched types
57+
--> $DIR/pretty.rs:24:74
58+
|
59+
LL | fn dyn_super_generic(x: &dyn for<'a> SuperGeneric<'a, Assoc = &'a u8>) { x }
60+
| - ^ expected `()`, found `&dyn SuperGeneric<'a, Assoc = &u8>`
61+
| |
62+
| help: try adding a return type: `-> &dyn for<'a> SuperGeneric<'a, for<'a> Assoc = &'a u8>`
63+
|
64+
= note: expected unit type `()`
65+
found reference `&dyn for<'a> SuperGeneric<'a, for<'a> Assoc = &'a u8>`
66+
67+
error[E0308]: mismatched types
68+
--> $DIR/pretty.rs:25:70
69+
|
70+
LL | fn dyn_any_generic(x: &dyn for<'a> AnyGeneric<'a, Assoc = &'a u8>) { x }
71+
| - ^ expected `()`, found `&dyn AnyGeneric<'a, Assoc = &u8>`
72+
| |
73+
| help: try adding a return type: `-> &dyn for<'a> AnyGeneric<'a, for<'a> Assoc = &'a u8>`
74+
|
75+
= note: expected unit type `()`
76+
found reference `&dyn for<'a> AnyGeneric<'a, for<'a> Assoc = &'a u8>`
77+
78+
error[E0308]: mismatched types
79+
--> $DIR/pretty.rs:26:60
80+
|
81+
LL | fn dyn_fixed_generic1(x: &dyn for<'a> FixedGeneric1<'a>) { x }
82+
| - ^ expected `()`, found `&dyn FixedGeneric1<'a, Assoc = &u8>`
83+
| |
84+
| help: try adding a return type: `-> &dyn for<'a> FixedGeneric1<'a, for<'a> Assoc = &'a u8>`
85+
|
86+
= note: expected unit type `()`
87+
found reference `&dyn for<'a> FixedGeneric1<'a, for<'a> Assoc = &'a u8>`
88+
89+
error[E0308]: mismatched types
90+
--> $DIR/pretty.rs:27:60
91+
|
92+
LL | fn dyn_fixed_generic2(x: &dyn for<'a> FixedGeneric2<'a>) { x }
93+
| - ^ expected `()`, found `&dyn FixedGeneric2<'a, Assoc = &u8>`
94+
| |
95+
| help: try adding a return type: `-> &dyn for<'a> FixedGeneric2<'a, for<'a> Assoc = &'a u8>`
96+
|
97+
= note: expected unit type `()`
98+
found reference `&dyn for<'a> FixedGeneric2<'a, for<'a> Assoc = &'a u8>`
99+
100+
error[E0308]: mismatched types
101+
--> $DIR/pretty.rs:28:78
102+
|
103+
LL | fn dyn_fixed_generic_multi(x: &dyn for<'a> FixedGeneric1<'a, Assoc = &u8>) { x }
104+
| - ^ expected `()`, found `&dyn FixedGeneric1<'a, Assoc = ..., Assoc = ...>`
105+
| |
106+
| help: try adding a return type: `-> &dyn for<'a> FixedGeneric1<'a, for<'a> Assoc = &u8, for<'a> Assoc = &'a u8>`
107+
|
108+
= note: expected unit type `()`
109+
found reference `&dyn for<'a> FixedGeneric1<'a, for<'a> Assoc = &u8, for<'a> Assoc = &'a u8>`
110+
111+
error[E0308]: mismatched types
112+
--> $DIR/pretty.rs:29:40
113+
|
114+
LL | fn dyn_fixed_hrtb(x: &dyn FixedHrtb) { x }
115+
| - ^ expected `()`, found `&dyn FixedHrtb<Assoc = &u8>`
116+
| |
117+
| help: try adding a return type: `-> &dyn FixedHrtb<for<'a> Assoc = &'a u8>`
118+
|
119+
= note: expected unit type `()`
120+
found reference `&dyn FixedHrtb<for<'a> Assoc = &'a u8>`
121+
122+
error: aborting due to 11 previous errors
123+
124+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)