Skip to content

internal: error on duplicate #[pin] attribute#120

Open
mentonin wants to merge 2 commits intoRust-for-Linux:mainfrom
mentonin:duplicate-pin
Open

internal: error on duplicate #[pin] attribute#120
mentonin wants to merge 2 commits intoRust-for-Linux:mainfrom
mentonin:duplicate-pin

Conversation

@mentonin
Copy link
Copy Markdown

adds the error and a compile_fail test to check for it.

Closes: #119

adds the error and a compile_fail test to check for it.

Closes: Rust-for-Linux#119

Signed-off-by: Luiz Georg <luizgngeorg@gmail.com>
@mentonin
Copy link
Copy Markdown
Author

I am new to both this project and Rust macros, but this problem seemed easy to tackle. Let me know if I should implement it with a different pattern instead.

I am also not sure if this should be documented on the CHANGELOG.md, or if the error/message should be different.

Co-authored-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Luiz Georg <luizgngeorg@gmail.com>
(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.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

multiple #[pin] attributes don't error

2 participants