-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
rewrite error handling for unresolved inference vars #89862
Conversation
This comment has been minimized.
This comment has been minimized.
5c814f9
to
8d53486
Compare
error[E0282]: type annotations needed | ||
--> $DIR/fn-needing-specified-return-type-param.rs:3:13 | ||
| | ||
LL | let _ = f; | ||
| - ^ cannot infer type for type parameter `A` declared on the function `f` | ||
| | | ||
| consider giving this pattern the explicit type `fn() -> A`, where the type parameter `A` is specified | ||
| ^ cannot infer type of the type parameter `A` declared on the function `f` | ||
| | ||
help: consider specifying the generic argument | ||
| | ||
LL | let _ = f::<A>; | ||
| +++++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with most of the results, but we do lose the special casing of assignments, where the stylistic solution is to give the binding a type, instead of leveraging the turbofish.
That shouldn't be a big problem, and we could remove a bunch of suggestion code by only relying on the new logic, but idealy it'd be nice if we could keep that.
I'll take a closer look at the logic later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, prioritizing assignments seems like the right choice, I am a bit torn however, because for
let x = returns_complex_type()
i would prefer to suggest let x = returns_complex_type::<T>()
instead of let x: SomeComplex<Type<T>, T>> = returns_complex_type()
. Maybe adding weights to each option, and prioritizing locals and closure parameters over generic arguments which are prioritized over closure return types or sth 🤔
help: consider specifying the generic arguments | ||
| | ||
LL | let x = |a: (), b: ()| -> Result<(), _> { | ||
| ++++++++++++++++ | ||
LL | Ok::<T, E>(b) | ||
| ++++++++ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is another case of what I was mentioning: The current suggestion is closer to what I'd want to recommend users do, and T
is already figured out (thanks to b
), the E
is the one that needs clarification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I quite dislike explicitly mentioning closure return types, so I would use Ok::<(); u32>
here.
I considered (at least partially) using the inferred generic args for the suggestion, but i don't think we always want to do this because sometimes the inferred types can be quite large. There's definitely quite a few possible improvements here however ^^ took me a while to understand how this code works and think that there are some pretty big wins here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the changes I'm making in #89427, we might be able to be explicit about the potentially usable types because we'll know all the impls that apply. And we already know that E
is the problematic one, so we can suggest Ok::<_, SomeE>
. Having said that, that doesn't need to be addressed yet, I think.
This comment has been minimized.
This comment has been minimized.
78d5028
to
d42c7ab
Compare
ping from triage: |
it's blocked on me taking a full day to work on this, should happen at some point during february 😆 |
fd6f822
to
411d565
Compare
This comment has been minimized.
This comment has been minimized.
⌛ Testing commit b343a46 with merge c5fda9cb3b4a0952fd3db63a3552dde0a1cba9b8... |
💔 Test failed - checks-actions |
@bors retry |
☀️ Test successful - checks-actions |
Finished benchmarking commit (e40d5e8): comparison url. Instruction count
Max RSS (memory usage)Results
CyclesThis benchmark run did not return any relevant results for this metric. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Footnotes |
@lcnr @estebank looks like this caused a perf regression. It's minor enough in primary benchmarks, but still worth looking into. I ran cache grind diff and saw that |
Node::PathSegment(seg) => { | ||
let ident_span = seg.ident.span; | ||
ident_span | ||
.with_hi(seg.args.map_or_else(|| ident_span.hi(), |args| args.span_ext.hi())) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would guess that the only thing which may impact the amount of process_obligations
would be this.
We now use a different span
from seg.ident
which may mean that we don't dedup obligations as readily as they now have different spans? Can try to take a deeper look at this in the near future
Pretty much completely rewrites
fn emit_inference_failure_err
.This new setup should hopefully be easier to extend and is already a lot better when looking for generic arguments.
Because this is a rewrite there are still some parts which are lacking, these are tracked in #94483 and will be fixed in later PRs.
r? @estebank @petrochenkov