-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Type errors of the form "expected... but found..." should indicate the source of their expectation #14007
Comments
Updated code:
Error
It still does not point to |
Triage: No change. |
Triage: the error message has improved but still does not point to the source of the expectation (playground).
|
We could probably add a Map<InferTy, Span> to InferCtxt and look at it whenever we encounter an error during inference. Though we may want to look at something that also works for concrete types, showing us where the type came from for all type mismatch errors. |
@oli-obk That effectively already exists, and is called the "origin" of the inference variable, and is already used by diagnostics. |
However, what's really lacking (and for good reasons - i.e. performance), is a "log" of unifications - you may end up with an inference variable, but have no clue as to what else it got unified with, on your way there. IMO the way to have our cake and eat it too would be to add a generic parameter to |
@eddyb you might be interested in looking at the giant hack in #106400, which relies exclusively on the HIR to find the expression where an expected type was inferred.
For the updated example in the first comment:
|
Point at expressions where inference refines an unexpected type Fix rust-lang#106355. Fix rust-lang#14007. (!) ``` error[E0308]: mismatched types --> src/test/ui/type/type-check/point-at-inference.rs:12:9 | 9 | foo.push(i); | - this is of type `&{integer}`, which makes `foo` to be inferred as `Vec<&{integer}>` ... 12 | bar(foo); | --- ^^^ expected `i32`, found `&{integer}` | | | arguments to this function are incorrect | = note: expected struct `Vec<i32>` found struct `Vec<&{integer}>` note: function defined here --> src/test/ui/type/type-check/point-at-inference.rs:2:4 | 2 | fn bar(_: Vec<i32>) {} | ^^^ ----------- help: consider dereferencing the borrow | 9 | foo.push(*i); | + ```
Add a 'open server logs' button to the error notification Closes rust-lang/rust-analyzer#13995 (comment) ![Code_pUQurJ9BRn](https://user-images.githubusercontent.com/3757771/214038673-658f3b43-5310-47b0-99da-d3222d173b0c.gif)
The program
gives the type error
This error should indicate the source of the expectation that the type parameter is integral.
The text was updated successfully, but these errors were encountered: