Uh oh!
There was an error while loading. Please reload this page.
reset default binding mode when we pass through a & pattern - #48448
Conversation
cramertj
commented
Feb 23, 2018
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: &i32let(x,&Some(Some(y))) = &(1,Some(Some(5)));// x: &i32// y: i32So the following would be an error: "cannot move out of borrowed content"? letOuter{&Inner{ x }} = &Outer{Inner{"".to_string()}};But this one would work: letOuter{&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. |
nikomatsakis
commented
Feb 23, 2018
Yes
Yes
Yes
OK |
nikomatsakis
commented
Feb 23, 2018
Actually @cramertj your first two examples were wrong: the other has a similar problem. |
nikomatsakis
commented
Feb 23, 2018
Actually, all of them do. |
nikomatsakis
commented
Feb 23, 2018
So maybe you were expecting different behavior. =) |
cramertj
commented
Feb 23, 2018
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 |
nikomatsakis
commented
Feb 23, 2018
@cramertj I see. I do sort of want the |
nikomatsakis
commented
Feb 23, 2018
@cramertj so r=you? |
cramertj
commented
Feb 23, 2018
@bors r+ |
bors
commented
Feb 23, 2018
📌 Commit 31f66a0 has been approved by |
…ssue-46688, r=cramertj reset default binding mode when we pass through a `&` pattern Fixesrust-lang#46688. r? @cramertj
Fixes#46688.
r? @cramertj