forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved bindings for
taken
and life_giver
to suit new lifetime rules.
- Loading branch information
Showing
1 changed file
with
2 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8ee3c94
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.
what's happening here? it's not obvious to me why the old pos was not good?
8ee3c94
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.
okay, so I'll use this as my first example to do a deep dive into the changes to region inference.
First off, here is a gist of the error message that you currently get from
rustc
: https://gist.github.com/pnkfelix/162eaab4433a434758b8(it is definitely not a good message. We have others that are worse, but the main problem I have with this one is that it says "reference must be valid for the block at 817:60 ... but borrowed value is only valid for the block at 817:60." At the very least, it would be better if the error message actually described two distinct blocks (or the destruction-scope versus user-scope for a block).
8ee3c94
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.
Hmm. The region inference constraint graph from the original source has about 73K nodes. Luckily for everyone it also has "only" about 73K edges.(oh wait, I may not have been looking at the correct ast node when I gathered that data ... i might have been somehow generating a region-graph for the whole impl...) Or something else is wrong with how-Z print-region-graph
is selecting the method data to print.But still, I suspect showing the graph of the original code is not going to be illuminating. (And plus, graphviz seems to be locking up attempting to process it.)
I will try to reduce it down to a smaller test case.
(I used my new
-xpretty everybody_loops
pretty printer to generate my starting point for this experiment, cut-and-pasting in the body ofErrorReporting for InferCtxt::give_suggestion
method. Here is an abuse of gist.github.com with that text: https://gist.github.com/pnkfelix/e734baaa17109dadf427 )8ee3c94
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.
Okay, so I narrowed the problem down to the following example:
Again, if you move
let life_giver = ...;
up above thelet expl_self = ...;
then it compiles.The thing I noted is that
expl_self
is crucially different from the other arguments to the originalRebuilder::new
:The other arguments are all of the form
&'a TYPE
, whileexpl_self
is of the formOption<&'a TYPE>
. I noticed that if I removeexpl_self
from the arguments, then the whole reduced example compiles again.I also noticed that in the reduced example, if I change things to try to emulate variance, like so:
then that also fixes things. I may actually try adopting that fix for this example, rather than continuing to play the game of "guess what spot will make all the inferred regions work out."
The question is: Should I attempt to fix this as part of this work? It seems like this is related to variance in some fashion, no? And thus is not really within scope for this PR...
8ee3c94
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 wrote:
This is probably not workable. My reduced example has
loop { }
as the body, so it misses the crucial detail that theexpr_self_opt
must end up as part of the returnedRebuilder<'a, 'tcx>
structure. So introducing an additional'b: 'a
is not really possible.8ee3c94
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.
3@nikomatsakis and I discussed offline. @nikomatsakis points out that in an example like this (which is a further simplified version of the problem encountered above):
the constraint-set cannot be solved under the new regime. The constraints in question are: the implicit lifetime in
&x
needs to outlive the scope oflet p = ...
, the implicit lifetime in&y
needs to be contained within the scope followinglet y = ...;
, and both lifetimes need to be compatible with the'a
infn constraints
.The current solution adopted in the PR (effectively moving
let y = ...;
up above thelet p = ...;
) is fine.A long-term option that we should investigate is: if we ever put in better variance handling for type parameters, then presumably the
p
binding can use one liftetime, and then when we pass it into the call to constraints, it can be restricted to the narrower sublifetime.(See also rust-lang#21198 )