Uh oh!
There was an error while loading. Please reload this page.
On type errors, show closure signature - #46350
Conversation
nikomatsakis
commented
Nov 29, 2017
Test? =) |
This is a bit as hoc and doesn't use type resolve to infer the args and return type. Is there a way to do it here, or should I keep it as simple as it is in this PR? The same can be done in ppaux (for the sake of consistent output). If we change it in ppaux I would like to keep the The difference would be |
bc45f33 to
89fcceaCompare89fccea to
1ac4442Comparenikomatsakis
commented
Nov 30, 2017
Well, leaving aside the mechanism, I'd like to know what you have in mind in terms of how you want things to look. I am not sure what I think about printing closure types as |
I believe that for the following code: fnclosure_to_loc(){letmut x = |c| c + 1;
x = |c| c + 1;}the output should be close to instead of (This PR does not implement the entirety of this as of yet.) |
bors
commented
Dec 2, 2017
☔ The latest upstream changes (presumably #46349) made this pull request unmergeable. Please resolve the merge conflicts. |
Instead of refering to closures with their span, format their signature.
1ac4442 to
541cfb4CompareI think that printing closures as I also think changing the way closures are printed in some error messages, but not all of them, is just going to confuse everyone when they see the error they are less familiar with. |
arielb1
commented
Dec 3, 2017
I think the main way you get closure types in type errors is when you have a type error containing a complicated type with a closure, and we need to avoid the closure "dominating" the error message by its ugliness. |
@arielb1 what do you think of referring to closures as That being said, I think it'd be nice to have a (pseudo)signature available in the type error output. |
Having multiple spans in a |
* Accept type errors where the closure was expected and/or found * Change closure presentation to `move |args| -> _` * Closure type error help and note don't point at span anymore * Update tests
4a411a3 to
9bfdbd9Comparearielb1
commented
Dec 3, 2017
As I said, the main way you get closures in error messages is in more complicated types. I need to find a few good situations so we can figure out how to cover them with error messages. |
| s.push_normal(format!("{}", tnm.ty)); | ||
| } | ||
| fn push_closure<'tcx>(capture: &hir::CaptureClause, |
There was a problem hiding this comment.
Is there any particular reason to scrape this information from the HIR? It can also be extracted from the closure type readily enough. To get the closure signature, you would do something like this (I have a more convenient helper for this on the nll-master branch, but it's not landed yet):
ty::TyClosure(did1, substs1) => {let closure_sig_ty = substs.closure_sig_ty(def_id,self.tcx);let closure_sig_ty = self.shallow_resolve(&closure_sig_ty);let sig:PolyFnSig<'_> = closure_sig_ty.fn_sig(self.tcx);}nikomatsakis
commented
Dec 5, 2017
I think this makes sense. It feels like there are a number of situations in which we want to a way to "extract out" more complex subparts of a type. Well, maybe not a number, I'm thinking primarily of the desire to be able to say something like "the type of this variable is
Is this a good idea to pursue? I'm not sure. Maybe. |
estebank
commented
Dec 6, 2017
@nikomatsakis I suggested something similar in #21025 (comment), I know that there is a ticket or comment where the same was proposed in more detail but couldn't find it. I think it is a worthwhile idea, specially for cases where we have |
nikomatsakis
commented
Dec 7, 2017
@estebank do you want to try pursuing that instead then, see how it feels? I like the idea of finding a way to "pull out" more detailed information, seems like it could be a big improvement overall; on the other hand, types appear in a lot of contexts. It feels like ideally we'd due some sort of revamp of the |
bors
commented
Dec 15, 2017
☔ The latest upstream changes (presumably #46641) made this pull request unmergeable. Please resolve the merge conflicts. |
kennytm
commented
Dec 20, 2017
Triage ping @estebank — @nikomatsakis has left some comments for this PR! BTW there is also merge conflict. |
estebank
commented
Dec 27, 2017
I'll close this PR in lieu of implementing the suggestion above sometime in the near future :) |
Instead of referring to closures with their span, format their signature.
r? @nikomatsakis
Fix#19939.