Skip to content

Unnecessary improper_ctypes warning for extern "Rust" #64593

Closed

Description

@josephlr

The following code generates an improper_ctypes warning:

extern "Rust" {
    fn foo(dest: &mut [u8]) -> Result<(), Error>;
}

I would expect this sort of warning for an extern "C" declaration, but it seems incorrect for an extern "Rust" declaration. Am I misunderstanding something, or is this a warning that is safe to disable?

Activity

  1. added
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    C-bugCategory: This is a bug.
    on Sep 18, 2019
  2. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Sep 19, 2019
  3. dhardy commented on Sep 20, 2019

    @dhardy
    Contributor

    For context, see: rust-random/getrandom#109

    Error is pub struct Error(NonZeroU32); so both this and Result are not C types.

  4. josephlr commented on Sep 20, 2019

    @josephlr
    ContributorAuthor

    Error is pub struct Error(NonZeroU32); so both this and Result are not C types.

    Also the &mut [u8] is not a C type either. The main issue seems to be that the compiler checks all extern declarations as if they were extern "C", which I don't think is right (but extern "Rust" isn't documented as much as extern "C").

  5. cuviper commented on Sep 20, 2019

    @cuviper
    Member

    There are instances of this in liballoc and libcore too:

    rust/src/liballoc/alloc.rs

    Lines 243 to 247 in 9ad1e7c

    #[allow(improper_ctypes)]
    extern "Rust" {
    #[lang = "oom"]
    fn oom_impl(layout: Layout) -> !;
    }

    // NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call
    #[allow(improper_ctypes)] // PanicInfo contains a trait object which is not FFI safe
    extern "Rust" {
    #[lang = "panic_impl"]
    fn panic_impl(pi: &PanicInfo<'_>) -> !;
    }

  6. self-assigned this
    on Sep 20, 2019
  7. added a commit that references this issue on Sep 21, 2019
    4cef643
  8. added 2 commits that reference this issue on Sep 21, 2019
    3a95540
    1486b7f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions