Skip to content

False positive improper_ctypes warning for () used through trait projection #66374

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
alexcrichton opened this issue Nov 13, 2019 · 4 comments
Closed
Labels
A-FFI Area: Foreign function interface (FFI) A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@alexcrichton
Copy link
Member

This code:

pub trait Foo {
    type Ret;
}

impl Foo for u32 {
    type Ret = ();
}

pub extern "C" fn foo() -> <u32 as Foo>::Ret {
}

generates this warning on nightly:

warning: `extern` fn uses type `()`, which is not FFI-safe
 --> src/lib.rs:9:28
  |
9 | pub extern "C" fn foo() -> <u32 as Foo>::Ret {
  |                            ^^^^^^^^^^^^^^^^^ not FFI-safe
  |
  = note: `#[warn(improper_ctypes)]` on by default
  = help: consider using a struct instead
  = note: tuples have unspecified layout

but I believe that this is an false positive because () in a return position is indeed FFI safe

@jonas-schievink jonas-schievink added A-FFI Area: Foreign function interface (FFI) A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 13, 2019
@Centril
Copy link
Contributor

Centril commented Nov 13, 2019

Duplicate of #66202?

@Centril
Copy link
Contributor

Centril commented Nov 13, 2019

cc @davidtwco @rkruppe @eddyb

@davidtwco
Copy link
Member

Duplicate of #66202?

I think so.

@hanna-kruppe
Copy link
Contributor

Agreed, closing as such.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-FFI Area: Foreign function interface (FFI) A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants