aboutsummaryrefslogtreecommitdiff
path: root/rust/helpers.c
diff options
context:
space:
mode:
authorBenno Lossin <[email protected]>2024-04-03 19:43:37 +0000
committerMiguel Ojeda <[email protected]>2024-05-05 18:05:00 +0200
commit9218cf826f1dbacbb857e6eabfae164d8ba05dea (patch)
tree907d661b0600f5fa83e91d97daaddb2e13f146f5 /rust/helpers.c
parenta0a4e17013f68739733028bba89673cdbb9caabd (diff)
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]>
Diffstat (limited to 'rust/helpers.c')
0 files changed, 0 insertions, 0 deletions