Skip to content
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

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

Closed
narpfel opened this issue May 31, 2024 · 0 comments · Fixed by #130667
Closed

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

narpfel opened this issue May 31, 2024 · 0 comments · Fixed by #130667
Labels
A-diagnostics Area: Messages for errors, warnings, and lints L-improper_ctypes Lint: improper_ctypes T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@narpfel
Copy link
Contributor

narpfel commented May 31, 2024

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

@narpfel narpfel added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 31, 2024
@workingjubilee workingjubilee added the L-improper_ctypes Lint: improper_ctypes label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints L-improper_ctypes Lint: improper_ctypes T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants