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

Explain type mismatch cause pointing to return type when it is impl Trait #57743

Closed
estebank opened this issue Jan 18, 2019 · 3 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@estebank
Copy link
Contributor

Point to the return type with an appropriate label on

fn foo() -> impl std::fmt::Display {
    if false {
        return 0i32;
    }
    1u64
}

An appropriate wording should be figured out, but it can be along the lines of

error[E0308]: mismatched types
  --> $DIR/point-to-type-err-cause-on-impl-trait-return.rs:5:5
   |
LL | fn foo() -> impl std::fmt::Display {
   |             ---------------------- expected because this `impl Trait` return type...
LL |     if false {
LL |         return 0i32;
   |                ---- ...gets coerced to `i32` here
LL |     }
LL |     1u32
   |     ^^^^ expected i32, found u64
   |
   = note: expected type `i32`
              found type `u64`

CC @nikomatsakis @zackmdavis @oli-obk @varkor who might have thoughts on wording.

@estebank estebank added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. A-diagnostics Area: Messages for errors, warnings, and lints labels Jan 18, 2019
@nikomatsakis
Copy link
Contributor

This would be awesome. I don't love the use of the word "coerced" in the label, perhaps something like "...is found to be i32 here" -- just because coercion I would prefer to reserve for a specific set of operations in Rust involving changing the value in some way (e.g., coercing from &Vec<T> to &[T])

Centril added a commit to Centril/rust that referenced this issue Jan 23, 2019
Explain type mismatch cause pointing to return type when it is `impl Trait`

Fix rust-lang#57743.
@bors bors closed this as completed in 8ef8d57 Jan 24, 2019
@ErichDonGubler
Copy link
Contributor

Quick nit that was initially confusing for me: in @estebank's OP example, the error says expected i32, found u64, but I'm pretty sure that what it's supposed to be is expected i32, foundu32, since the second literal in the example is 1u32 and not 1u64.

@ErichDonGubler
Copy link
Contributor

Also, Esteban: You're awesome for putting so much hard work into Rust's diagnostics. Rock on!

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 E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

3 participants