Skip to content

improper_ctypes behaves weird around function pointers #42050

Closed
@retep998

Description

@retep998
#![deny(improper_ctypes)]

// Intentionally not #[repr(C)]
pub struct Foo;

#[repr(C)] // Expect error here that Bar is marked repr(C) but contains fn ptr referencing non-repr(C) type
pub struct Bar {
    // Alternatively expect error here that extern fn contains type that is non-repr(C).
    pub f: unsafe extern "system" fn(arg: *const Foo)
}

extern "system"{
    pub fn baz(bar: *const Bar); // Actually get error here implying Bar is not marked repr(C) even though it is
}

fn main() {

}
error: found non-foreign-function-safe member in struct marked #[repr(C)]: found struct without foreign-function-safe representation annotation in foreign module, consider adding a #[repr(C)] attribute to the type
  --> src/main.rs:12:21
   |
12 |     pub fn baz(bar: *const Bar); // Actually get error here implying Bar is not marked repr(C) even though it is
   |                     ^^^^^^^^^^
   |
note: lint level defined here
  --> src/main.rs:1:9
   |
1  | #![deny(improper_ctypes)]
   |         ^^^^^^^^^^^^^^^

error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions