Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upPermit `-> _` return types for improved diagnostics #56132
Comments
varkor
added
A-diagnostics
T-compiler
labels
Nov 21, 2018
This comment has been minimized.
This comment has been minimized.
|
This change would potentially set precedent for treating specific invalid/incomplete code specially in ways that are not reflected in valid code. In other words:
This was originally proposed by @eddyb on Discord. Relevant conversation:
|
This comment has been minimized.
This comment has been minimized.
|
As this potentially sets precedent for diagnostic-motivated behaviour changes, it seems prudent to check that there aren't any concerns with doing this. @rfcbot merge |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Nov 21, 2018
•
|
Team member @varkor has proposed to merge this. The next step is review by the rest of the tagged team members:
Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
rfcbot
added
proposed-final-comment-period
disposition-merge
labels
Nov 21, 2018
This comment has been minimized.
This comment has been minimized.
|
Note that the implementation difficulty of this should be negligible, becuase we alrrady have on-demand queries, and we can switch between "check body against signature" and "get signature from body" trivially. |
eddyb
added
E-easy
E-mentor
labels
Nov 21, 2018
This comment has been minimized.
This comment has been minimized.
|
I support this precedent, and think it obviates things like rust-lang/rfcs#2479 |
This comment has been minimized.
This comment has been minimized.
|
Why is |
This comment has been minimized.
This comment has been minimized.
|
The difference is that calls to the function would also know about the return type and not produce additional fallout. Basically return type inference like |
This comment has been minimized.
This comment has been minimized.
|
@rfcbot concern unneeded An alternative would be to carry optional inferred type information on
or just completely elide the error in line 6 by checking against both the resolved type ( |
This comment has been minimized.
This comment has been minimized.
leonardo-m
commented
Nov 21, 2018
•
|
I think in the Haskell world for something like this they invent a pretty name (something like Return Type Holes) and write a paper on it. |
This comment has been minimized.
This comment has been minimized.
|
@estebank That's not actionable because it breaks with cycles (think recursive function) - and we don't want to add recovery from dependency cycles. The way it works with |
This comment has been minimized.
This comment has been minimized.
|
Couldn't this (changing |
This comment has been minimized.
This comment has been minimized.
|
@estebank No, that sort of side-effect is incompatible with the incremental dataflow ("query") model. |
This comment has been minimized.
This comment has been minimized.
Obviously I disagree that it obviates that change; this will still error, not letting you finish That said I fully support this change. |
This comment has been minimized.
This comment has been minimized.
FrankSD
commented
Dec 9, 2018
|
Is this issue already taken? Please confirm I would like to take this on |
This comment has been minimized.
This comment has been minimized.
|
@FrankSD: it's not, but you'll want to wait until the FCP has (started and) finished before working on this, to avoid wasting time if the FCP does not pass. |
This comment has been minimized.
This comment has been minimized.
|
I have philosophical disagreements with this idea, as I'd prefer the compiler to not need this (as I see it) kludge and instead provide better diagnostics with more advanced inference, but I understand the pragmatic reasoning behind it. +1 |
This comment has been minimized.
This comment has been minimized.
|
It's hard to produce disagnostics if you can't parse the source. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
FrankSD
commented
Apr 1, 2019
|
Anyone still working on this? |
This comment has been minimized.
This comment has been minimized.
|
@estebank: you need to resolve your previous concern, for FCP to begin. |
varkor commentedNov 21, 2018
•
edited
Consider (the invalid Rust code containing) a function that returns a value, but has no return type:
Currently, the compiler produces these errors:
In theory, the only problem is the missing return type, which, if provided, would cause the code to compile successfully.
The compiler knows what the return type should be here, and could potentially interpret the rest of the program as if the correct return type were given.
This issue proposes giving special treatment in the compiler for diagnostics only (note that this is not a language change) to the syntax
-> _for return types. This would report a normal error for a missing return type (no extra code would compile after this change), but would otherwise treat the function as having the missing return type. A machine-applicable suggestion would be provided to replace_with the correct return type.For example: