-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Enforce tail call type is related to body return type in borrowck #144917
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
base: master
Are you sure you want to change the base?
Enforce tail call type is related to body return type in borrowck #144917
Conversation
r? @WaffleLapkin though lcnr can review it too if they want, this change should be pretty straightforward. |
|
} else { | ||
ConstraintCategory::UseAsConst | ||
} | ||
if is_diverging { |
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 don't really care about the ordering here but the true
branch seemed easier to put first
4504cdb
to
a573fd9
Compare
@bors r+ rollup |
Like all call terminators, tail call terminators instantiate the binder of the callee signature with region variables and equate the arg operand types with that signature's args to ensure that the call is valid.
However, unlike normal call terminators, we were forgetting to also relate the return type of the call terminator to anything. In the case of tail call terminators, the correct thing is to relate it to the return type of the caller function (or in other words, the return local
_0
).This meant that if the caller's return type had some lifetime constraint, then that constraint wouldn't flow through the signature and affect the args.
This is what's happening in the example test I committed:
Specifically, the type
x
is'?0 str
, where'?0
is some universal arg. The type ofpassthrough
isfn(&'?1 str) -> &'?1 str
. Equating the args sets'?0 = '?1
. However, we need to also equate the return type&'?1 str
to&'static str
so that we eventually require that'?0 = 'static
, which is a borrowck error!Look at the first commit for the functional change, and the second commit is just a refactor because we don't need to pass
Option<BasicBlock>
tocheck_call_dest
, but just whether or not the terminator is expected to be diverging (i.e. if the return type is!
).Fixes #144916