Skip to content

extern "rust-cold" fns should not trigger improper_ctypes lint #125830

Closed
@narpfel

Description

@narpfel

Code

#![feature(rust_cold_cc)]

pub extern "rust-cold" fn f(_: ()) -> Result<(), ()> {
    Ok(())
}

extern "rust-cold" {
    pub fn g(_: ()) -> Result<(), ()>;
}

Current output

warning: `extern` fn uses type `()`, which is not FFI-safe
 --> <source>:3:32
  |
3 | pub extern "rust-cold" fn f(_: ()) -> Result<(), ()> {
  |                                ^^ not FFI-safe
  |
  = help: consider using a struct instead
  = note: tuples have unspecified layout
  = note: `#[warn(improper_ctypes_definitions)]` on by default

warning: `extern` fn uses type `Result<(), ()>`, which is not FFI-safe
 --> <source>:3:39
  |
3 | pub extern "rust-cold" fn f(_: ()) -> Result<(), ()> {
  |                                       ^^^^^^^^^^^^^^ not FFI-safe
  |
  = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
  = note: enum has no representation hint

warning: `extern` block uses type `()`, which is not FFI-safe
 --> <source>:8:17
  |
8 |     pub fn g(_: ()) -> Result<(), ()>;
  |                 ^^ not FFI-safe
  |
  = help: consider using a struct instead
  = note: tuples have unspecified layout
  = note: `#[warn(improper_ctypes)]` on by default

warning: `extern` block uses type `Result<(), ()>`, which is not FFI-safe
 --> <source>:8:24
  |
8 |     pub fn g(_: ()) -> Result<(), ()>;
  |                        ^^^^^^^^^^^^^^ not FFI-safe
  |
  = help: consider adding a `#[repr(C)]`, `#[repr(transparent)]`, or integer `#[repr(...)]` attribute to this enum
  = note: enum has no representation hint

warning: 4 warnings emitted

Desired output

<<no warnings>>

Rationale and extra context

(godbolt link)

Like extern "Rust" and the other extern "rust-*" ABIs, extern "rust-cold" should not trigger improper_ctypes and improper_ctypes_definitions for non-FFI-safe types.

Related: #64593, #64641; tracking issue #97544.

Other cases

No response

Rust Version

$ rustc --version --verbose
rustc 1.80.0-nightly (6f3df08aa 2024-05-30)
binary: rustc
commit-hash: 6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4
commit-date: 2024-05-30
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.6

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsL-improper_ctypesLint: improper_ctypesT-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