-
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 inference reports misleading diagonstics #69455
Comments
It gets even more misleading if you use fn main() {
let xs: Vec<u64> = vec![1, 2, 3];
let ys: Vec<u64> = xs.iter().map(|i: &u64| i*2).collect();
let _: u64 = 23u64 + xs.iter().sum();
} This gives the following error:
This doesn't even report the line where the actual error is which is even more misleading. Imagine if there were several other lines between line 3 and 4. Edit: Added explicit type to the map closure parameter to show it's still the same error. |
@SkiFire13 Thank you for your additional information. |
This solves the method call part of issue rust-lang#69455 I added a `target_span` field so as to pin down the exact location of the error. We need a dedicated field `found_exact_method_call` to prioritize situations like the test case `issue-69455.rs`. If we reuse `found_method_call`, `found_local_pattern` will show up first. We can not move `found_method_call` up, it is undesirable in various situations.
…or, r=estebank fix misleading type annotation diagonstics This solves the method call part of issue rust-lang#69455
Current output has a slight mistake in the span suggestion, I suspect due to the macro :-/
The second example has the same problem:
|
I accidentally fixed that in a6d6589#diff-7f900f1a55b5da3794eca56bf34b4c0f473f32a8f78b4a04842b578f8e819e90 Edit: to clarify, this is not yet merged. It's now part of #106770, and might become part of #106745 depending on perf results. |
@m-ou-se drive by fixes ftw 🚗 |
Looks like my change that accidentally fixes this causes a performance regression, so I won't include it in my PR for now. It does provide an interesting data point for this issue, though: If Arguments::new_v1(…, &[
ArgumentV1::new_display(&(23u64 + xs.iter().sum()))
]) then the problematic suggestion appears. It attempts to suggest to add an explicit But if it expands to Arguments::new_v1(…, &match (&(23u64 + xs.iter().sum()),) {
args => [ArgumentV1::new_display(args.0)]
}) then it instead suggests adding an explicit |
@m-ou-se could that change on its own be landed, or would that also cause perf (or other) problems? It seems like it'd be safe to slightly change the desugaring to aid in this. |
It is specifically that one change that causes the performance regression. (Regardless of my other changes.) The extra |
@m-ou-se would you mind publishing that change as a PR assigned to me? (don't include the |
…estebank Deprioritize fulfillment errors that come from expansions. Fixes (part of?) rust-lang#69455
Given that it is fixed and no longer reproducible, maybe this issue should be closed? |
Current output:
|
I tried this code:
I expected to see this happen: I expect rust to tell me I should be more precise about
23u64 + xs.iter().sum()
.Instead, this happened:
A method call variant of this problem is
The only difference is that
self.test
is a method call, while+
is a binary operator.rustc --version --verbose
Related issue: #69214
The text was updated successfully, but these errors were encountered: