Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl trait error does not explain its reasoning #93327

Open
oli-obk opened this issue Jan 26, 2022 · 0 comments
Open

impl trait error does not explain its reasoning #93327

oli-obk opened this issue Jan 26, 2022 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Jan 26, 2022

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1497daa8a96b61decc37bed908eec352

use std::fmt::Display;

trait Foo {
    type Bar;
}

impl Foo for () {
    type Bar = Vec<i32>;
}

fn foo() -> impl Foo<Bar = impl Display> {
    ()
}

The current output is:

error[E0277]: `Vec<i32>` doesn't implement `std::fmt::Display`
  --> src/main.rs:11:13
   |
11 | fn foo() -> impl Foo<Bar = impl Display> {
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Vec<i32>` cannot be formatted with the default formatter
   |
   = help: the trait `std::fmt::Display` is not implemented for `Vec<i32>`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead

Ideally the output should look like:

error[E0277]: `Vec<i32>` doesn't implement `std::fmt::Display`
  --> src/main.rs:11:13
   |
11 | fn foo() -> impl Foo<Bar = impl Display> {
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `Vec<i32>` cannot be formatted with the default formatter
   |
   = help: the trait `std::fmt::Display` is not implemented for `Vec<i32>`
   = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
note: required due to associated type of `impl Foo for ()`
   | 
 9 |     type Bar = Vec<i32>;
   |                ^^^^^^^^
@oli-obk oli-obk added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. labels Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant