Rust: Include type bindings on string representation of `impl Trait`

Created on 13 Aug 2019  路  13Comments  路  Source: rust-lang/rust

_Follow up to https://github.com/rust-lang/rust/pull/63507#discussion_r313287274_

Include type arguments for traits when displaying impl Trait. For example, the following:

error[E0282]: type annotations needed for `impl std::future::Future`
  --> $DIR/cannot-infer-async-enabled-impl-trait-bindings.rs:14:9
   |
LL |     let fut = async {
   |         --- consider giving `fut` the explicit type `impl std::future::Future`, with the type parameters specified
LL |         make_unit()?;
   |         ^^^^^^^^^^^^ cannot infer type

should be

error[E0282]: type annotations needed for `impl std::future::Future`
  --> $DIR/cannot-infer-async-enabled-impl-trait-bindings.rs:14:9
   |
LL |     let fut = async {
   |         --- consider giving `fut` the explicit type `impl std::future::Future<Output=_>`, with the type parameters specified
LL |         make_unit()?;
   |         ^^^^^^^^^^^^ cannot infer type


A-async-await A-diagnostics AsyncAwait-Triaged C-enhancement P-medium T-compiler

Most helpful comment

This issue seems to be about associated type bindings, but the title mentions type parameters.
The whole to_opt_poly_trait_ref check results in hiding all the bounds that aren't trait bounds.

Due to impl Foo + Bar existing, I think this is harder than the dyn Trait case, because you have to pair up projection bounds to the right trait, kind of like how rustdoc does for displaying something nicer.

This makes me think E-easy is not the right label, but I'm not sure yet.
In the future please cc me on all ty::print-related issues/PRs.

cc @nikomatsakis @matthewjasper

All 13 comments

@rustbot claim

Should have time tonight. 馃檪

I'll probably better wait until #63507 is merged 馃槉

@iluuu1994 that should happen sometime today.

@estebank Would you mind giving me a few pointers? I looked through the source code but it wasn't completely obvious to me on how to achieve this. Is this already supported by the FmtPrinter or something new that has to be implemented?

I'm not sure if this codepath is using FmtPrinter (I did a quick check changing this to "im pl " and I didn't see any change to this error. I _think_ that what you want to look at is

https://github.com/rust-lang/rust/blob/afc39bbf2447844569e872468f9440d430b81a46/src/librustc/ty/print/mod.rs#L212-L255

and make it use the _substs, but again, I'm not 100% sure that is the case.

I will try that, thanks @estebank 馃檪

It's less than ideal, but using RUSTC_LOG=rustc::ty::print=debug causes a stack overflow, which makes it harder to figure out what's going on:

thread 'rustc' has overflowed its stack
fatal runtime error: stack overflow
Abort trap: 6

Thanks! Sorry I've just not gotten around to it. Hopefully tonight 馃槉

@iluuu1994 Are you still working on this? If not, I can grab it :)

@oliviabrown9 Nope, feel free to take over.

This issue seems to be about associated type bindings, but the title mentions type parameters.
The whole to_opt_poly_trait_ref check results in hiding all the bounds that aren't trait bounds.

Due to impl Foo + Bar existing, I think this is harder than the dyn Trait case, because you have to pair up projection bounds to the right trait, kind of like how rustdoc does for displaying something nicer.

This makes me think E-easy is not the right label, but I'm not sure yet.
In the future please cc me on all ty::print-related issues/PRs.

cc @nikomatsakis @matthewjasper

@rustbot release-assignment

Was this page helpful?
0 / 5 - 0 ratings