[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230720131935.3542850-1-aliceryhl@google.com>
Date: Thu, 20 Jul 2023 13:19:35 +0000
From: Alice Ryhl <aliceryhl@...gle.com>
To: benno.lossin@...ton.me
Cc: alex.gaynor@...il.com, aliceryhl@...gle.com,
bjorn3_gh@...tonmail.com, boqun.feng@...il.com, gary@...yguo.net,
linux-kernel@...r.kernel.org, nmi@...aspace.dk, ojeda@...nel.org,
rust-for-linux@...r.kernel.org, wedsonaf@...il.com
Subject: Re: [PATCH v2 05/12] rust: init: make initializer values inaccessible
after initializing
> Previously the init macros would create a local variable with the name
> and hygiene of the field that is being initialized to store the value of
> the field. This would override any user defined variables. For example:
> ```
> struct Foo {
> a: usize,
> b: usize,
> }
> let a = 10;
> let foo = init!(Foo{
> a: a + 1, // This creates a local variable named `a`.
> b: a, // This refers to that variable!
> });
> let foo = Box::init!(foo)?;
> assert_eq!(foo.a, 11);
> assert_eq!(foo.b, 11);
> ```
>
> This patch changes this behavior, so the above code would panic at the
> last assertion, since `b` would have value 10.
>
> Signed-off-by: Benno Lossin <benno.lossin@...ton.me>
Reviewed-by: Alice Ryhl <aliceryhl@...gle.com>
Powered by blists - more mailing lists