Add checkup for return statement outside of a function#37780
Add checkup for return statement outside of a function#37780bors merged 5 commits intorust-lang:masterfrom
Conversation
4a4a471 to
a519c40
Compare
|
Please use an informative title, the error number means nothing. |
|
Didn't pay attention, I thought it took first commit's message by default. My bad. |
There was a problem hiding this comment.
returning a value in a function that returns ()
a519c40 to
94d21b5
Compare
There was a problem hiding this comment.
How about "return can only be used inside a function body"?
It seems a bit odd to do this in regionck ... but I see that for (e.g.) a constant we use the type of the constant as the return type. That seems strange to me! I wonder how hard it would be to change that -- I'd rather have FnCtxt have a Option<Ty<'tcx>> as the return type, or at least do the flag in librustc_typeck/check/mod.rs and not regionck.
What do you think @eddyb ?
There was a problem hiding this comment.
I'm fine with banning it earlier - return for constant values only makes sense in MIR anyway.
There was a problem hiding this comment.
So I guess it's not getting merged any time soon... :-/
There was a problem hiding this comment.
Just have to move it to ExprRet type-checking, should be straight-forward (except for the condition not being region-related).
There was a problem hiding this comment.
Wording is not the best here. return foo is an expression according to the reference, and in the example you want to remove only the return and not the entire statement.
There was a problem hiding this comment.
Considering the statement/expression grammatical categories, return is an expression according to the reference. So to say "remove the return statement" is imprecise because it's an expression, and misleading because the user might try to remove the entire expression when he should only remove the return keyword.
There was a problem hiding this comment.
Oh I see now. I really didn't understand the first time. :-/
Thanks! :)
6442ec8 to
c843fa2
Compare
nikomatsakis
left a comment
There was a problem hiding this comment.
Looking better! :) I left some suggestions on wording and also a request to move the ret_ty as a parameter to new
There was a problem hiding this comment.
Nit: "return statement outside of function body" feels like clearer wording to me. "cannot be out of a function scope" doesn't quite seem grammatical; also, the term "fn scope" is not (I think) quite so standard.
There was a problem hiding this comment.
Nit: "A return statement was found outside of a function body."
There was a problem hiding this comment.
(This would have to be updated too)
There was a problem hiding this comment.
Huh. It feels weird to me to not have the ret_ty get passed into the constructor. I see that we (one time) reassigned it later, but now it seems like we almost always do. I think I'd rather we continue to pass in a Option<> into new as an argument.
There was a problem hiding this comment.
It has to be computed after the fcx is created anyway, AFAICT (not here though).
There was a problem hiding this comment.
From my changes, it was always updated outside so it doesn't change much AFAICT.
There was a problem hiding this comment.
The majority of cases do not need to recompute it, from what I can tell. Basically 3/4 :). In one of those cases, the default of None suffices. So I think it's better to pass it as an argument -- harder to forget that you may want to assign it.
There was a problem hiding this comment.
It may well be though that in those other cases, None would also suffice-- I suspect so.
|
☔ The latest upstream changes (presumably #37717) made this pull request unmergeable. Please resolve the merge conflicts. |
c843fa2 to
34fe31d
Compare
|
Updated. |
There was a problem hiding this comment.
here it does not need to be recomputed
There was a problem hiding this comment.
here it does not need to be recomputed
There was a problem hiding this comment.
The majority of cases do not need to recompute it, from what I can tell. Basically 3/4 :). In one of those cases, the default of None suffices. So I think it's better to pass it as an argument -- harder to forget that you may want to assign it.
There was a problem hiding this comment.
It may well be though that in those other cases, None would also suffice-- I suspect so.
|
@bors: r=nikomatsakis |
|
📌 Commit dd938bc has been approved by |
|
⌛ Testing commit dd938bc with merge f42e53f... |
|
💔 Test failed - auto-win-gnu-32-opt-rustbuild |
|
@nikomatsakis: @eddyb: We have quite a huge issue here in |
|
I wonder if the MIR sanity checker should use |
|
@eddyb: |
|
@rust-lang/compiler What should we do about MIR typeck and |
|
@eddyb Hmm. I am not crazy about having the MIR type-checker use I am not crazy about it because my plan is to use the MIR type-checker as the basis for region checking, and I guess that in that mode, we would want to behave like the real region checker. I think we should use |
|
So, what should I do about this? |
|
☔ The latest upstream changes (presumably #38097) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@nikomatsakis: Seems like the last master update fixed the issue. Should be ready to get merged! |
|
Ok, so someone added an E0571 meanwhile so I had to update mine to E0572. Should be good now. |
|
@GuillaumeGomez still has an X...do you see why? |
|
Travis is broken -- it fails this way on all PRs before running most of the tests. |
|
Just like @jseyfried said. New rustbuild issue if I'm not mistaken. I r+ in your name, don't hesitate to r- if you see anything. @bors: r=nikomatsakis |
|
📌 Commit ed3c483 has been approved by |
Add checkup for return statement outside of a function Fixes #37778. r? @eddyb (don't know who is in charge. Don't hesitate to set another one) cc @jonathandturner
Fixes #37778.
r? @eddyb (don't know who is in charge. Don't hesitate to set another one)
cc @jonathandturner