Stream: general

Topic: who expects a type?


Jake Goulding (May 12 2020 at 17:50, on Zulip):

@Esteban Küber for the "expected type foo found bar" style messages, who is "expecting"? Can we change that to explicitly say what expects it?

Jake Goulding (May 12 2020 at 17:52, on Zulip):

Updating

error[E0308]: mismatched types
 --> src/main.rs:4:10
  |
4 |     demo("hi");
  |          ^^^^ expected `i32`, found `&str`

to

error[E0308]: mismatched types
 --> src/main.rs:4:10
  |
4 |     demo("hi");
  |          ^^^^ the function `demo` expected `i32`, found `&str`

maybe even

expected this argument to be a `i32`, but it is `&str`

Jake Goulding (May 12 2020 at 18:14, on Zulip):

I guess this does occur sometimes:

--- expected `f64` because of return type
kennytm (May 12 2020 at 18:20, on Zulip):

some cases do highlight the site of expectation like

error[E0308]: mismatched types
 --> src/main.rs:5:18
  |
5 |     let b: i32 = "123";
  |            ---   ^^^^^ expected `i32`, found `&str`
  |            |
  |            expected due to this
kennytm (May 12 2020 at 18:21, on Zulip):

though most of the time i do find E0308 confusing because it is not very clear whether the marked expression is the "expected" or the "found"

Jake Goulding (May 12 2020 at 18:22, on Zulip):

My gut tells me that if we say what / why it's expected (more frequently, perhaps), then it would be more quickly digested. I'm pretty sure I've trained my brain to just ignore the "expected" / "found" text.

Esteban Küber (May 12 2020 at 19:01, on Zulip):

The pointed element should always be the found one

Esteban Küber (May 12 2020 at 19:01, on Zulip):

The problem we have is that these cases usually come from obligations

Esteban Küber (May 12 2020 at 19:02, on Zulip):

I've been working in this but the cases that are left are becoming harder and harder

Esteban Küber (May 12 2020 at 19:02, on Zulip):

And sadly I'm many cases all I can do is reconstruct what went wrong because we drop a lot of info during typeck

Esteban Küber (May 12 2020 at 19:02, on Zulip):

Keeping that info around would balloon mem usage, which is a no-no

simulacrum (May 12 2020 at 19:28, on Zulip):

@Esteban Küber I wonder if we've explored e.g. re-running typeck in "collection" mode if it detects an error at first to gather better explanations

simulacrum (May 12 2020 at 19:29, on Zulip):

I'd guess it'd be pretty hard to make that work well? But I don't think I've seen PRs in that direction at all

Esteban Küber (May 12 2020 at 19:37, on Zulip):

I've looked into it, but I doubt well ever get good at global analysis as things stand. Anything inside a given FnCtxt has potential

Last update: May 29 2020 at 18:05UTC