Skip to content
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

Document that @ pattern can now introduce new bindings #148

Closed
maxwase opened this issue Oct 22, 2021 · 2 comments
Closed

Document that @ pattern can now introduce new bindings #148

maxwase opened this issue Oct 22, 2021 · 2 comments

Comments

@maxwase
Copy link

maxwase commented Oct 22, 2021

Since Rust 1.56.0 you can run this code:

fn main() {
    let a @ b @ c = 1;
    println!("{} {} {}", a, b, c); // 1 1 1
}

PR
playground

@ralfbiedert
Copy link
Owner

Jesus that's hideous ...

@ralfbiedert
Copy link
Owner

ralfbiedert commented Oct 22, 2021

How is that even supposed to work, if I do

let mut a @ mut b @ c = 1;
b = 2;
dbg!(a);

It prints 1, but aren't they meant to bind the same memory location?

...

I mean, ok, in line with the above this here doesn't compile:

struct S(u8);

let a @ b @ c = S(123);

So in a sense this doesn't really bind the underlying thing trice, but just creates 3 copies. This is probably the ugliest language concept I've come across but I like your example for outlining this weird behavior. I'd love if someone could sleuth a good (authoritative) link we can add for further reading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants