Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions internal/src/pin_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,13 @@ pub(crate) fn pin_data(
.map(|field| {
let len = field.attrs.len();
field.attrs.retain(|a| !a.path().is_ident("pin"));
(len != field.attrs.len(), &*field)
let diff = len - field.attrs.len();
if diff > 1 {
return Err(dcx.error(field, "#[pin] attribute specified more than once"));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of returning an error, could you just report the error and continue? This way it prevents cascading of error caused by not generating any code.

}
Ok((diff > 0, &*field))
})
.collect();
.collect::<Result<_, _>>()?;

for (pinned, field) in &fields {
if !pinned && is_phantom_pinned(&field.ty) {
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/compile-fail/pin_data/twice_pin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use pin_init::*;

#[pin_data]
struct Foo {
#[pin]
#[pin]
a: usize,
}

fn main() {}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add a user of Foo here, you should observe the "cascading error" effect

5 changes: 5 additions & 0 deletions tests/ui/compile-fail/pin_data/twice_pin.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: #[pin] attribute specified more than once
--> tests/ui/compile-fail/pin_data/twice_pin.rs:7:5
|
7 | a: usize,
| ^^^^^^^^
Loading