Skip to content

Commit cc88d52

Browse files
committed
internal: error on duplicate #[pin] attribute
adds the error and a compile_fail test to check for it. Closes: #119 Signed-off-by: Luiz Georg <luizgngeorg@gmail.com>
1 parent bbf992b commit cc88d52

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

internal/src/pin_data.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,13 @@ pub(crate) fn pin_data(
7979
.map(|field| {
8080
let len = field.attrs.len();
8181
field.attrs.retain(|a| !a.path().is_ident("pin"));
82-
(len != field.attrs.len(), &*field)
82+
let diff = len - field.attrs.len();
83+
if diff > 1 {
84+
return Err(dcx.error(field, "#[pin] attribute set twice"));
85+
}
86+
Ok((diff > 0, &*field))
8387
})
84-
.collect();
88+
.collect::<Result<_, _>>()?;
8589

8690
for (pinned, field) in &fields {
8791
if !pinned && is_phantom_pinned(&field.ty) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use pin_init::*;
2+
3+
#[pin_data]
4+
struct Foo {
5+
#[pin]
6+
#[pin]
7+
a: usize,
8+
}
9+
10+
fn main() {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: #[pin] attribute set twice
2+
--> tests/ui/compile-fail/pin_data/twice_pin.rs:7:5
3+
|
4+
7 | a: usize,
5+
| ^^^^^^^^

0 commit comments

Comments
 (0)