summaryrefslogtreecommitdiff
path: root/rust/helpers.c
diff options
context:
space:
mode:
authorBenno Lossin <benno.lossin@proton.me>2024-04-03 19:43:37 +0000
committerMiguel Ojeda <ojeda@kernel.org>2024-05-05 18:05:00 +0200
commit9218cf826f1dbacbb857e6eabfae164d8ba05dea (patch)
tree907d661b0600f5fa83e91d97daaddb2e13f146f5 /rust/helpers.c
parenta0a4e17013f68739733028bba89673cdbb9caabd (diff)
downloadlwn-9218cf826f1dbacbb857e6eabfae164d8ba05dea.tar.gz
lwn-9218cf826f1dbacbb857e6eabfae164d8ba05dea.zip
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 <benno.lossin@proton.me> Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/rust-for-linux/1e8a2a1f-abbf-44ba-8344-705a9cbb1627@proton.me/ [1] Link: https://lore.kernel.org/r/20240403194321.88716-1-benno.lossin@proton.me [ Added Benno's link and Gary's simplified example. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust/helpers.c')
0 files changed, 0 insertions, 0 deletions