add test for pretty printing trait objects
This commit is contained in:
parent
d4f6f9ee6a
commit
fd9202109b
2 changed files with 155 additions and 0 deletions
31
tests/ui/traits/object/pretty.rs
Normal file
31
tests/ui/traits/object/pretty.rs
Normal file
|
@ -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() {}
|
124
tests/ui/traits/object/pretty.stderr
Normal file
124
tests/ui/traits/object/pretty.stderr
Normal file
|
@ -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`.
|
Loading…
Add table
Reference in a new issue