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

Return type that doesn't satisfy `impl Trait` messages should point out the reason #44530

Open
estebank opened this Issue Sep 12, 2017 · 0 comments

Comments

Projects
None yet
2 participants
@estebank
Copy link
Contributor

estebank commented Sep 12, 2017

Currently, for the following code where a function's signature returns an impl Trait that isn't implemented by the actual return type:

#![feature(conservative_impl_trait)]

trait T {}

struct S;

fn foo() -> impl T {
    return 1;
}

provides the following output:

error[E0277]: the trait bound `{integer}: T` is not satisfied
 --> src/main.rs:7:13
  |
7 | fn foo() -> impl T {
  |             ^^^^^^ the trait `T` is not implemented for `{integer}`
  |
  = note: the return type of a function must have a statically known size

An appropriate output would at the very least need to be:

error[E0277]: the trait bound `{integer}: T` is not satisfied
 --> src/main.rs:7:13
  |
7 | fn foo() -> impl T {
  |             ^^^^^^ the trait `T` is not implemented for `{integer}`
8 |     return 1;
  |     ^^^^^^^^ `{integer}` is returned here

On cases where the returned type is local to the project, the declaration of the type should be pointed out

#![feature(conservative_impl_trait)]

trait T {}

struct S;

fn foo() -> impl T {
    S
}
error[E0277]: the trait bound `S: T` is not satisfied
 --> src/main.rs:7:13
  |
7 | fn foo() -> impl T {
  |             ^^^^^^ the trait `T` is not implemented for `S`
8 |     S
  |     ^ `S` is returned here
note: `S`'s definition:
  |
5 | struct S;
  | ^^^^^^^^
note: `T`'s definition:
  |
3 | trait T {}
  | ^^^^^^^^^^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment