Skip to content
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

Change how scope of & is computed #2979

Closed
nikomatsakis opened this issue Jul 21, 2012 · 0 comments
Closed

Change how scope of & is computed #2979

nikomatsakis opened this issue Jul 21, 2012 · 0 comments
Assignees
Labels
A-lifetimes Area: Lifetimes / regions C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@nikomatsakis
Copy link
Contributor

Right now we compute the scope of an expression like &expr in a pre-determined fashion. What we should do is to create a region variable and use that instead, with a lower bound of the &expr itself but no upper bound (we should also use this technique for implicit borrows). Inference will then select the smallest scope it can for the resulting region. Finally, in borrowck, make sure that expr can be guaranteed for the result. This will require some modifications to borrowck, I think, to be sure it takes loops and so forth into account for rooting—but that code makes sense to have anyway.

The reason to make this change is that it allows us to select the lifetime of &expr in a variety of ways. If expr is a shared box, or owned by a shared box, we can use the rooting rules which can sometimes be the best. Otherwise, we can use the lifetime of expr itself, which is sometimes the right choice. Basically we can't know until after inference what would be the true upper bound and so we have to check later in a second pass. This isn't a very clear bug report but I'll draw up some examples in the code of what I mean.

This enhancement helps with sendable hashtables and would allow us to do things like return pointers to the interior of data structures in more cases.

@ghost ghost assigned nikomatsakis Jul 21, 2012
RalfJung pushed a commit to RalfJung/rust that referenced this issue Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

1 participant