-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Two-phase borrows don't allow mutably splitting an array based on its length #53723
Comments
Nominating for triage. |
This has to do with two-phase not affecting auto-slicing, if we pre-slice it works: #![feature(nll)]
fn main() {
let x = &mut [1, 2][..];
x.split_at_mut(x.len() / 2);
} Whereas the original example compiles & checks like this: #![feature(nll)]
fn main() {
let mut x = [1, 2];
(&mut x as &mut [_]).split_at_mut((&mut x as &mut [_]).len() / 2);
} |
@eddyb yes, that was my suspicion, though I realize now that there won't be an easy fix, since we need the auto-slicing to convert from |
I think this is likely a "won't fix" -- but we should accumulate examples where 2PB fails to live up to its promises (and I would count this among them). |
Seasoned Rust hackers are probably already aware of this, but here's another way to get the effect described by @eddyb which may be more in line typical code in the wild. (Namely, add a type annotation to force the auto-slice to occur earlier.) #![feature(nll)]
fn main() {
let x: &mut [u32] = &mut [1, 2];
x.split_at_mut(x.len() / 2);
} |
We discussed expanding two-phase borrows in our weekly meeting on Tuesday and ultimately settled on "not right now but maybe later", so I'm marking this as deferred. |
1.30.0-nightly (2018-08-24 d41f21f)
/cc @nikomatsakis @pnkfelix
The text was updated successfully, but these errors were encountered: