Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse unsafe in attributes #1013

Closed
Coekjan opened this issue Oct 18, 2024 · 5 comments
Closed

Parse unsafe in attributes #1013

Coekjan opened this issue Oct 18, 2024 · 5 comments

Comments

@Coekjan
Copy link
Contributor

Coekjan commented Oct 18, 2024

See https://blog.rust-lang.org/2024/10/17/Rust-1.82.0.html#unsafe-attributes

Now attributes can contain unsafe, but cbindgen gives the following error:

ParseSyntaxError { crate_name: "...", src_path: "...", error: Error("expected identifier, found keyword `unsafe`") }

I think this issue could be urgent (should be done before edition 2024), because programmers, like me, may write:

#[unsafe(export_name = "xxx")]
pub fn f() {

}

Current rust stable (1.82.x) introduces this syntax and recommends us to add unsafe, while the old form (without unsafe) is still acceptable. But the old form will be a hard error in edition 2024.


This issue seems actually from upstream: dtolnay/syn#1710

@Coekjan
Copy link
Contributor Author

Coekjan commented Oct 20, 2024

Because dtolnay/syn#1710 is done, all we need is to wait for the next release of syn.

@Coekjan Coekjan closed this as completed Oct 20, 2024
@qryxip
Copy link

qryxip commented Oct 21, 2024

Not yet completed, I think. The current cbindgen itself does not know unsafe attributes.

fn is_no_mangle(&self) -> bool {
self.has_attr_word("no_mangle")
}

They are now parsed indeed, but just skipped.

@Coekjan
Copy link
Contributor Author

Coekjan commented Oct 22, 2024

Not yet completed, I think. The current cbindgen itself does not know unsafe attributes.

fn is_no_mangle(&self) -> bool {
self.has_attr_word("no_mangle")
}

They are now parsed indeed, but just skipped.

Yes, you are right. cbindgen should visit the inner of the unsafe attributes.

@emilio
Copy link
Collaborator

emilio commented Oct 27, 2024

Fixed by #1020, thanks @Coekjan!

@emilio emilio closed this as completed Oct 27, 2024
@Coekjan
Copy link
Contributor Author

Coekjan commented Oct 27, 2024

Fixed by #1020, thanks @Coekjan!

@emilio Could you please make a new release? My project needs this feature (to parse unsafe attributes).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants