forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#120739 - lukas-code:pp-dyn-assoc, r=compile…
…r-errors improve pretty printing for associated items in trait objects * Don't print a binder in front of associated items, because it's not valid syntax. * e.g. print `dyn for<'a> Trait<'a, Assoc = &'a u8>` instead of `dyn for<'a> Trait<'a, for<'a> Assoc = &'a u8>`. * Don't print associated items that are implied by a supertrait bound. * e.g. if we have `trait Sub: Super<Assoc = u8> {}`, then just print `dyn Sub` instead of `dyn Sub<Assoc = u8>`. I've added the test in the first commit, so you can see the diff of the compiler output in the second commit.
- Loading branch information
Showing
6 changed files
with
281 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Test for pretty-printing trait object types. | ||
|
||
trait Super { | ||
type Assoc; | ||
} | ||
trait Any: Super {} | ||
trait Fixed: Super<Assoc = u8> {} | ||
trait FixedSub: Fixed {} | ||
trait FixedStatic: Super<Assoc = &'static u8> {} | ||
|
||
trait SuperGeneric<'a> { | ||
type Assoc2; | ||
} | ||
trait AnyGeneric<'a>: SuperGeneric<'a> {} | ||
trait FixedGeneric1<'a>: SuperGeneric<'a, Assoc2 = &'a u8> {} | ||
trait FixedGeneric2<'a>: Super<Assoc = &'a u8> {} | ||
trait FixedHrtb: for<'a> SuperGeneric<'a, Assoc2 = &'a u8> {} | ||
trait AnyDifferentBinders: for<'a> SuperGeneric<'a, Assoc2 = &'a u8> + Super {} | ||
trait FixedDifferentBinders: for<'a> SuperGeneric<'a, Assoc2 = &'a u8> + Super<Assoc = 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_fixed_static(x: &dyn FixedStatic) { x } //~ERROR mismatched types | ||
|
||
fn dyn_super_generic(x: &dyn for<'a> SuperGeneric<'a, Assoc2 = &'a u8>) { x } //~ERROR mismatched types | ||
fn dyn_any_generic(x: &dyn for<'a> AnyGeneric<'a, Assoc2 = &'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, Assoc2 = &u8>) { x } //~ERROR mismatched types | ||
fn dyn_fixed_hrtb(x: &dyn FixedHrtb) { x } //~ERROR mismatched types | ||
fn dyn_any_different_binders(x: &dyn AnyDifferentBinders<Assoc = u8>) { x } //~ERROR mismatched types | ||
fn dyn_fixed_different_binders(x: &dyn FixedDifferentBinders) { x } //~ERROR mismatched types | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/pretty.rs:21: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:22: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:23:31 | ||
| | ||
LL | fn dyn_fixed(x: &dyn Fixed) { x } | ||
| - ^ expected `()`, found `&dyn Fixed` | ||
| | | ||
| help: try adding a return type: `-> &dyn Fixed` | ||
| | ||
= note: expected unit type `()` | ||
found reference `&dyn Fixed` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/pretty.rs:24:50 | ||
| | ||
LL | fn dyn_fixed_multi(x: &dyn Fixed<Assoc = u16>) { x } | ||
| - ^ expected `()`, found `&dyn Fixed<Assoc = u16>` | ||
| | | ||
| help: try adding a return type: `-> &dyn Fixed<Assoc = u16>` | ||
| | ||
= note: expected unit type `()` | ||
found reference `&dyn Fixed<Assoc = u16>` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/pretty.rs:25:38 | ||
| | ||
LL | fn dyn_fixed_sub(x: &dyn FixedSub) { x } | ||
| - ^ expected `()`, found `&dyn FixedSub` | ||
| | | ||
| help: try adding a return type: `-> &dyn FixedSub` | ||
| | ||
= note: expected unit type `()` | ||
found reference `&dyn FixedSub` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/pretty.rs:26:44 | ||
| | ||
LL | fn dyn_fixed_static(x: &dyn FixedStatic) { x } | ||
| - ^ expected `()`, found `&dyn FixedStatic` | ||
| | | ||
| help: try adding a return type: `-> &dyn FixedStatic` | ||
| | ||
= note: expected unit type `()` | ||
found reference `&dyn FixedStatic` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/pretty.rs:28:75 | ||
| | ||
LL | fn dyn_super_generic(x: &dyn for<'a> SuperGeneric<'a, Assoc2 = &'a u8>) { x } | ||
| - ^ expected `()`, found `&dyn SuperGeneric<'a, Assoc2 = &u8>` | ||
| | | ||
| help: try adding a return type: `-> &dyn for<'a> SuperGeneric<'a, Assoc2 = &'a u8>` | ||
| | ||
= note: expected unit type `()` | ||
found reference `&dyn for<'a> SuperGeneric<'a, Assoc2 = &'a u8>` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/pretty.rs:29:71 | ||
| | ||
LL | fn dyn_any_generic(x: &dyn for<'a> AnyGeneric<'a, Assoc2 = &'a u8>) { x } | ||
| - ^ expected `()`, found `&dyn AnyGeneric<'a, Assoc2 = &u8>` | ||
| | | ||
| help: try adding a return type: `-> &dyn for<'a> AnyGeneric<'a, Assoc2 = &'a u8>` | ||
| | ||
= note: expected unit type `()` | ||
found reference `&dyn for<'a> AnyGeneric<'a, Assoc2 = &'a u8>` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/pretty.rs:30:60 | ||
| | ||
LL | fn dyn_fixed_generic1(x: &dyn for<'a> FixedGeneric1<'a>) { x } | ||
| - ^ expected `()`, found `&dyn FixedGeneric1<'a>` | ||
| | | ||
| help: try adding a return type: `-> &dyn for<'a> FixedGeneric1<'a>` | ||
| | ||
= note: expected unit type `()` | ||
found reference `&dyn for<'a> FixedGeneric1<'a>` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/pretty.rs:31:60 | ||
| | ||
LL | fn dyn_fixed_generic2(x: &dyn for<'a> FixedGeneric2<'a>) { x } | ||
| - ^ expected `()`, found `&dyn FixedGeneric2<'a>` | ||
| | | ||
| help: try adding a return type: `-> &dyn for<'a> FixedGeneric2<'a>` | ||
| | ||
= note: expected unit type `()` | ||
found reference `&dyn for<'a> FixedGeneric2<'a>` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/pretty.rs:32:79 | ||
| | ||
LL | fn dyn_fixed_generic_multi(x: &dyn for<'a> FixedGeneric1<'a, Assoc2 = &u8>) { x } | ||
| - ^ expected `()`, found `&dyn FixedGeneric1<'a, Assoc2 = ...>` | ||
| | | ||
| help: try adding a return type: `-> &dyn for<'a> FixedGeneric1<'a, Assoc2 = &u8>` | ||
| | ||
= note: expected unit type `()` | ||
found reference `&dyn for<'a> FixedGeneric1<'a, Assoc2 = &u8>` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/pretty.rs:33:40 | ||
| | ||
LL | fn dyn_fixed_hrtb(x: &dyn FixedHrtb) { x } | ||
| - ^ expected `()`, found `&dyn FixedHrtb` | ||
| | | ||
| help: try adding a return type: `-> &dyn FixedHrtb` | ||
| | ||
= note: expected unit type `()` | ||
found reference `&dyn FixedHrtb` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/pretty.rs:34:73 | ||
| | ||
LL | fn dyn_any_different_binders(x: &dyn AnyDifferentBinders<Assoc = u8>) { x } | ||
| - ^ expected `()`, found `&dyn AnyDifferentBinders<Assoc = ...>` | ||
| | | ||
| help: try adding a return type: `-> &dyn AnyDifferentBinders<Assoc = u8>` | ||
| | ||
= note: expected unit type `()` | ||
found reference `&dyn AnyDifferentBinders<Assoc = u8>` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/pretty.rs:35:65 | ||
| | ||
LL | fn dyn_fixed_different_binders(x: &dyn FixedDifferentBinders) { x } | ||
| - ^ expected `()`, found `&dyn FixedDifferentBinders` | ||
| | | ||
| help: try adding a return type: `-> &dyn FixedDifferentBinders` | ||
| | ||
= note: expected unit type `()` | ||
found reference `&dyn FixedDifferentBinders` | ||
|
||
error: aborting due to 14 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.