Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rust: init: change the generated name of guard variables
The initializers created by the `[try_][pin_]init!` macros utilize the guard pattern to drop already initialized fields, when initialization fails mid-way. These guards are generated to have the same name as the field that they handle. To prevent namespacing issues [1] when the field name is the same as e.g. a constant name, add `__` as a prefix and `_guard` as the suffix. [ Gary says: "Here's the simplified example: ``` macro_rules! f { () => { let a = 1; let _: u32 = a; } } const a: u64 = 1; fn main() { f!(); } ``` The `a` in `f` have a different hygiene so normally it is scoped to the macro expansion and wouldn't escape. Interestingly a constant is still preferred despite the hygiene so constants escaped into the macro, leading to the error." - Miguel ] Signed-off-by: Benno Lossin <[email protected]> Reviewed-by: Boqun Feng <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/rust-for-linux/[email protected]/ [1] Link: https://lore.kernel.org/r/[email protected] [ Added Benno's link and Gary's simplified example. - Miguel ] Signed-off-by: Miguel Ojeda <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> (cherry picked from commit 9218cf826f1dbacbb857e6eabfae164d8ba05dea)
- Loading branch information