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 modules and unsafe extern blocks #270

Merged
merged 9 commits into from
Aug 29, 2020
Merged

Parse unsafe modules and unsafe extern blocks #270

merged 9 commits into from
Aug 29, 2020

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Aug 29, 2020

Requires rust-lang/rust#75857.

For now the keywords are parsed but ignored, but the idea is that in a future release we would rely on unsafe extern for the syntactic safety claim that unsafe on the function declarations within have been accurately prescribed.

#[cxx::bridge]
mod ffi {
    unsafe extern "C++" {
        fn f();  // safe to call, unsafe to declare
        unsafe fn g();  // unsafe to call, safe to declare
    }
}

We would enforce that the extern block is unsafe unless all functions inside it have been declared unsafe, in which case the extern block is not making a safety claim that these functions are safe to call.

@dtolnay dtolnay merged commit 3c01ac2 into master Aug 29, 2020
@dtolnay dtolnay deleted the parse branch August 29, 2020 22:50
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 this pull request may close these issues.

1 participant