-
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
reset default binding mode when we pass through a &
pattern
#48448
reset default binding mode when we pass through a &
pattern
#48448
Conversation
I'm adding some examples here to make sure I understand the behavior: let (x, &(y, ref z)) = &(1, (2, 3));
// x: &i32
// y: i32
// z: &i32
let (x, &Some(Some(y))) = &(1, Some(Some(5)));
// x: &i32
// y: i32 So the following would be an error: "cannot move out of borrowed content"? let Outer { &Inner { x } } = &Outer { Inner { "".to_string() } }; But this one would work: let Outer { &Inner { ref x } } = &Outer { Inner { "".to_string() } }; It seems a little bit odd that If you're feeling up to it, I wouldn't mind having more tests of this sort in order to more clearly demonstrate the desired behavior, but basically r=me. |
Yes
Yes
Yes
OK |
Actually @cramertj your first two examples were wrong:
the other has a similar problem. |
Actually, all of them do. |
So maybe you were expecting different behavior. =) |
Okay, I guess that makes sense-- it's switching the binding mode, but still pattern-matching normally using the reference pattern. So this will only work for dereferencing values which were references originally. This seems like an unfortunate limitation-- it would be nice to be able to specify that other values should be taken by-value-- this would basically make |
@cramertj I see. I do sort of want the |
@cramertj so r=you? |
@bors r+ |
📌 Commit 31f66a0 has been approved by |
…ssue-46688, r=cramertj reset default binding mode when we pass through a `&` pattern Fixes rust-lang#46688. r? @cramertj
Fixes #46688.
r? @cramertj