Skip to content

Order of extern and unsafe is backwards in trait definitions and impls #19398

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

Closed
ftxqxd opened this issue Nov 29, 2014 · 1 comment · Fixed by #19418
Closed

Order of extern and unsafe is backwards in trait definitions and impls #19398

ftxqxd opened this issue Nov 29, 2014 · 1 comment · Fixed by #19418

Comments

@ftxqxd
Copy link
Contributor

ftxqxd commented Nov 29, 2014

trait Foo {
    extern "Rust" unsafe fn foo();
}

impl Foo for () {
    extern "Rust" unsafe fn foo() {}
}

unsafe extern "Rust" fn foo() {}

fn main() {}

Here unsafe comes after extern in the Foo’s definition and implementation, but it comes before in the extern in the top-level function foo. I think foo’s order seems the most natural (and would be the most common use anyway), so I would assume that it has the intended order.

@alexcrichton
Copy link
Member

Nominating, seems bad.

ftxqxd added a commit to ftxqxd/rust that referenced this issue Nov 30, 2014
This breaks code that looks like this:

    trait Foo {
        extern "C" unsafe fn foo();
    }

    impl Foo for Bar {
        extern "C" unsafe fn foo() { ... }
    }

Change such code to look like this:

    trait Foo {
        unsafe extern "C" fn foo();
    }

    impl Foo for Bar {
        unsafe extern "C" fn foo() { ... }
    }

Fixes rust-lang#19398.

[breaking-change]
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.

2 participants