-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Incorrect borrow checking #39963
Comments
This is intentional. rust-lang/rfcs#130. |
@arielb1 no... it isn't. This is incorrect behavior. It should treat (as seen by the fact that it works in the outer match statement) |
@ubsan I'm afraid @arielb1 is right, we really dumbed down |
@eddyb then it's a bug with the specification (and the issue should be left open). |
given that this works: https://is.gd/clzryh, rust should be able to figure out the difference between a moving deref and a non-moving; it can already figure out mutable vs. non-mutable. |
Sure, the equivalent of your code with a #[derive(Clone)]
struct BoxFoo;
impl std::ops::Deref for BoxFoo {
type Target = Foo;
fn deref(&self) -> &Foo { panic!() }
}
impl std::ops::DerefMut for BoxFoo {
fn deref_mut(&mut self) -> &mut Foo { panic!() }
}
#[derive(Clone)]
struct Foo(Option<BoxFoo>, Option<BoxFoo>);
fn test(f: &mut Foo) {
match *f {
Foo(Some(ref mut left), Some(ref mut right)) => match **left {
Foo(Some(ref mut left), Some(ref mut right)) => panic!(),
_ => panic!(),
},
_ => panic!(),
}
}
fn main() {
} The current borrowck is sort-of in maintenance mode, so this is unlikely to be fixed before MIR borrowck. |
Nominating. I suggest we retag this as C-enhancement rather than C-bug. I separately suggest that we prioritize it as P-medium. (It does not need to land as part of the initial MIR-borrowck / NLL work.) |
(looking at #23610, I am wondering: what's the difference between C-feature-request and C-enhancement? Should we collapse those two labels into one...?) |
In the NLL / MIR borrow checker, we decided to just be smarter around |
I think I would be happy to just add a test for this (with |
Tests that rust-lang#39963 is fixed on MIR borrowck As title. fixes rust-lang#39963
Rollup of 7 pull requests Successful merges: - #50852 (Add doc comment to hiding portions of code example) - #51183 (Update rustdoc book to suggest using Termination trait instead of hidden ‘foo’ function) - #51255 (Fix confusing error message for sub_instant) - #51256 (Fix crate-name option in rustdoc) - #51308 (Check array indices in constant propagation) - #51343 (test: Ignore some problematic tests on sparc and sparc64) - #51358 (Tests that #39963 is fixed on MIR borrowck) Failed merges:
UPDATE: This now works in NLL land. We just need someone to add a test.
https://is.gd/O6RlWi
left.1.0
andleft.0.0
should be separate borrows into the same structure.Note that changing
**left
to*&mut**left
makes it borrow check, and changingBox<Foo>
to&'static mut Foo
in theFoo
struct also makes it borrow check. This makes me think it's something to do with the special casing ofBox
.The text was updated successfully, but these errors were encountered: