Skip to content

rustc: Enable writing "unsafe extern fn() {}" #14005

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

Merged
merged 1 commit into from
May 7, 2014

Conversation

alexcrichton
Copy link
Member

Previously, the parser would not allow you to simultaneously implement a
function with a different abi as well as being unsafe at the same time. This
extends the parser to allow functions of the form:

unsafe extern fn foo() {
    // ...
}

The closure type grammar was also changed to reflect this reversal, types
previously written as "extern unsafe fn()" must now be written as
"unsafe extern fn()". The parser currently has a hack which allows the old
style, but this will go away once a snapshot has landed.

Closes #10025

[breaking-change]

@alexcrichton
Copy link
Member Author

A consequence of this is that extern "Rust" fn() is the same as fn() in how it's treated and how it's printed. Is that undesirable?

@@ -398,9 +398,9 @@ impl fmt::Show for clean::Type {
write!(f.buf, "{}{}fn{}{}",
FnStyleSpace(decl.fn_style),
match decl.abi {
Copy link
Member

Choose a reason for hiding this comment

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

This could be

match decl.abi.as_slice() {
    "" => " extern ".to_owned(),
    "\"Rust\"" => "".to_owned(),
    s => format!(" extern {} ", s)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed! Updated.

Previously, the parser would not allow you to simultaneously implement a
function with a different abi as well as being unsafe at the same time. This
extends the parser to allow functions of the form:

    unsafe extern fn foo() {
        // ...
    }

The closure type grammar was also changed to reflect this reversal, types
previously written as "extern unsafe fn()" must now be written as
"unsafe extern fn()". The parser currently has a hack which allows the old
style, but this will go away once a snapshot has landed.

Closes rust-lang#10025

[breaking-change]
@@ -876,7 +876,6 @@ pub struct FnDecl {
pub enum FnStyle {
UnsafeFn, // declared with "unsafe fn"
NormalFn, // declared with "fn"
ExternFn, // declared with "extern fn"
Copy link
Member

Choose a reason for hiding this comment

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

This has been bugging me for a while, thanks :).

bors added a commit that referenced this pull request May 7, 2014
Previously, the parser would not allow you to simultaneously implement a
function with a different abi as well as being unsafe at the same time. This
extends the parser to allow functions of the form:

    unsafe extern fn foo() {
        // ...
    }

The closure type grammar was also changed to reflect this reversal, types
previously written as "extern unsafe fn()" must now be written as
"unsafe extern fn()". The parser currently has a hack which allows the old
style, but this will go away once a snapshot has landed.

Closes #10025

[breaking-change]
@bors bors closed this May 7, 2014
@bors bors merged commit 08237ca into rust-lang:master May 7, 2014
@alexcrichton alexcrichton deleted the extern-unsafe branch May 7, 2014 23:37
bors pushed a commit to rust-lang-ci/rust that referenced this pull request Jan 28, 2025
I'll take a short break from auto assignments. My last few weeks have
been busy and I feel like getting my inbox back in order and taking a
short breather will be the best for me.

I still plan to review the PRs I'm currently assigned to and writing the
changelogs.

Jup that's it, have a good day, who ever is reading this =^.^=

changelog: none
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.

Can't define unsafe extern "C" fn
6 participants