summaryrefslogtreecommitdiff
path: root/tools/lib/python/kdoc
diff options
context:
space:
mode:
authorMohamad Alsadhan <mo@sdhn.cc>2026-09-04 15:12:32 +0100
committerGary Guo <gary@garyguo.net>2026-09-14 01:37:02 +0100
commit3b3ff9034a497fb3b8429f6fe8ba5697bc7dcebd (patch)
tree6843c2b19c7e08e37b9a9d310b1b2f0c06156e8c /tools/lib/python/kdoc
parentd48aa955cb91745ef2e5089f9277a7a95060cce3 (diff)
downloadlinux-next-3b3ff9034a497fb3b8429f6fe8ba5697bc7dcebd.tar.gz
linux-next-3b3ff9034a497fb3b8429f6fe8ba5697bc7dcebd.zip
rust: pin-init: internal: init: support tuple struct constructor syntax
A tuple struct whose fields are all set to a value reads better written like a call to its constructor than with the indices spelled out: pin_init!(Foo(value, value)) Parse the two forms into separate types and rewrite the constructor arguments into the indexed fields they are shorthand for, so that only the parser has to know about the second form. The arguments have no names, so they cannot use `<-`. Parse it anyway and reject it afterwards, which reports the position of every offending `<-` rather than stopping at the first one. `cfg` needs different treatment for tuple constructor syntax. As non-derive proc macros are invoked before cfg is resolved, the macro cannot know whether a field survives, and dropping a tuple field renumbers every field after it. That cannot be expressed by attaching a `cfg` attribute to the initializer of a single field. Thus, resolve tuple field cfgs up front instead, by generating two cfg-gated invocations of the macro with one field resolved in each. This is the approach of commit 5bbf2b2deb94 ("rust: pin-init: internal: rework how `#[pin_data]` handles cfg"), and it is linear time because only one of the two branches is ever expanded. Struct expression syntax do not renumber, so using tuple structs with struct syntax can keep using the existing attribute-based handling. Suggested-by: Gary Guo <gary@garyguo.net> Link: https://github.com/Rust-for-Linux/pin-init/pull/165 Signed-off-by: Mohamad Alsadhan <mo@sdhn.cc> [ Pre-expand cfgs for tuple init syntax. Use generics instead of separate types for normalization - Gary ] Co-developed-by: Gary Guo <gary@garyguo.net> Link: https://patch.msgid.link/20260904-tuple-struct-v1-4-72c50bd037fd@garyguo.net Signed-off-by: Gary Guo <gary@garyguo.net>
Diffstat (limited to 'tools/lib/python/kdoc')
0 files changed, 0 insertions, 0 deletions