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

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

Reported-by: Mohamad Alsadhan <[email protected]>
Closes: https://github.com/Rust-for-Linux/pin-init/issues/119
Signed-off-by: Luiz Georg <[email protected]>
Link: https://patch.msgid.link/[email protected]
[ Reworded commit message, and change the logic so code generation still
  continue after reporting error - Gary ]
Signed-off-by: Gary Guo <[email protected]>
This commit is contained in:
Luiz Georg authored and Gary Guo committed 2026-07-13 12:08:46 +01:00
1 parent a13c140cc2
commit f26f2f22c6
1 file changed
+5 -2
+5 -2
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,
}
})