-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tracking issue for generalized two-phase borrows #49434
Comments
I've become less convinced that we will actually want generalized two-phase borrows, as I commented earlier, (quoted here for convenient reference:
|
Here is a sample code that highlights the deficiency of the current formulation: fn main() {
let mut x = vec![];
x.push(x.len());
x.get_mut(x.len());
println!("Hello, world!");
} which results in
This is baffling because the |
In terms of re-triaging for #56754, I think this is NLL-complete, P-medium. |
I ran into a very similar issue, borrow-after-move, where a generalized two-phase solution would help and would make behaviours more as expected. |
This comment has been minimized.
This comment has been minimized.
Visting for T-compiler backlog bonanza. I'm still of the opinion that I don't want us to invest too much effort in generalizing two-phase borrows without more formal proof of its soundness. The new T-types team is in the best spot to produce that. So, moving this to T-types and adding S-tracking-design-concerns:
@rustbot label: -T-compiler +T-types +S-tracking-design-concerns |
This can be sort-of considered a tracking issue for the implementation of rust-lang/rfcs#2025
Right now, two phase borrow support can only handle the very simple case where there is exactly one activation point. In particular, this means we can't expose two-phase borrows to user code since the following wouldn't work:
We also intentionally limit two-phase borrows to a very narrow subset of its possible applications; specifically cases where the compiler is injecting mutable auto borrows which are used as method/function parameters. In practice, this covers the following cases:
x.some_method()
syntax, where some_method takes &mut selfFoo::some_method(&mut x, ...)
syntaxIndexMut
operations at this timeBasically, things that desugar to method calls with a mutable self parameter with the exception of
IndexMut
. The intention with these restrictions is leverage two-phase borrows to make MIR borrowck accept AST borrowck can, without introducing too much new flexibility (ref #48431 for a more detailed discussion of how and why this came to be). The eventual intention (per rust-lang/rfcs#2025) is to extend this to the general case outlined above, which is what this issue tracks.The text was updated successfully, but these errors were encountered: