rust: pin-init: internal: error on duplicate #[pin] attribute

Duplicated `#[pin]` has no effect, thus error if misused.

Reported-by: Mohamad Alsadhan <mo@sdhn.cc>
Closes: https://github.com/Rust-for-Linux/pin-init/issues/119
Signed-off-by: Luiz Georg <luizgngeorg@gmail.com>
Link: https://patch.msgid.link/20260710-pin-init-sync-v1-1-8fa16cde87ae@garyguo.net
[ Reworded commit message, and change the logic so code generation still
  continue after reporting error - Gary ]
Signed-off-by: Gary Guo <gary@garyguo.net>
This commit is contained in:
Luiz Georg
2026-07-10 17:20:31 +01:00
committed by Gary Guo
parent a13c140cc2
commit f26f2f22c6

View File

@@ -85,7 +85,10 @@ pub(crate) fn pin_data(
.map(|field| {
let len = field.attrs.len();
field.attrs.retain(|a| !a.path().is_ident("pin"));
let pinned = len != field.attrs.len();
let pinned_count = len - field.attrs.len();
if pinned_count > 1 {
dcx.error(&field, "#[pin] attribute specified more than once");
}
let cfg_attrs = field
.attrs
@@ -95,7 +98,7 @@ pub(crate) fn pin_data(
FieldInfo {
field: &*field,
pinned,
pinned: pinned_count != 0,
cfg_attrs,
}
})