Re: [PATCH v2 05/12] rust: init: make initializer values inaccessible after initializing

From: Martin Rodriguez Reboredo
Date: Thu Jul 20 2023 - 20:25:56 EST


On 7/19/23 11:20, Benno Lossin wrote:
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@xxxxxxxxx>
---
[...]
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@xxxxxxxxx>