-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Why doesn't let (&x, &y) = &(t, t,)
work?
#71730
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
Comments
Afaik this is intended behavior. You don't have a tuple of references but a reference to a tuple. fn foo2() {
let c = (1i32, 2i32);
let &(x, y) = &c;
// This works
} |
Thanks. |
Thinking more about this, i still think it's a little weird that this doesn't work. // this works fine
fn foo3((a, b): &(i32, i32)) {
}
// this doesn't
fn foo4((&a, &b): &(i32, i32)) { } I think this should work for consistency, because there should only be one meaning for |
But this does work: fn foo4(&(a, b): &(i32, i32)) {} I think pattern matching is consistent here. |
Some additional variations with explicit types if it helps make the current behavior clearer: fn main() {
let c: (u8, u8) = (0, 1);
//
let (x, y): &(u8, u8) = &c;
let _: (&u8, &u8) = (x, y);
//
let (ref x, ref y): &(u8, u8) = &c;
let _: (&u8, &u8) = (x, y);
//
let &(x, y): &(u8, u8) = &c;
let _: (u8, u8) = (x, y);
//
let (x, y): &(u8, u8) = &c;
let (&x, &y): (&u8, &u8) = (x, y);
let _: (u8, u8) = (x, y);
//
let &(x, ref y): &(u8, u8) = &c;
let _: (u8, &u8) = (x, y);
}
fn foo3((a, b): &(i32, i32)) {
let _: &i32 = a;
let _: &i32 = b;
}
fn foo3_2((ref a, ref b): &(i32, i32)) {
let _: &i32 = a;
let _: &i32 = b;
}
// fn foo4((&a, &b): &(i32, i32)) {}
fn foo4_2(&(a, b): &(i32, i32)) {
let _: i32 = a;
let _: i32 = b;
} The RFC for match ergonomics might help clarify the current binding modes: |
Sorry, i still feel i'm missing something important here, i'm not finding a way to express myself, but just examining the rules and design goals. Let me list my way of thinking and assumptions :( fn foo3(&(a, ref b): &(i32, i32)) {
} currently works. fn foo3((&a, b): &(i32, i32)) {
} Conceptually should work exactly as the previous program. However it doesn't. |
let (&x, &y) = &(t, t,)
work?
Closing as a duplicate of #64586 (feel free to reopen if I misunderstood) |
I'm not sure whether this is a bug or not, feel free to close if it's not.
I tried this code:
I expected to see this happen: Everything compiles fine, since components of the tuple are all
Copy
.Instead, this happened: The second case fails with bad diagnostics.
The text was updated successfully, but these errors were encountered: