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

Unnecessary improper_ctypes warning for extern "Rust" #64593

Closed
josephlr opened this issue Sep 18, 2019 · 3 comments · Fixed by #64641
Closed

Unnecessary improper_ctypes warning for extern "Rust" #64593

josephlr opened this issue Sep 18, 2019 · 3 comments · Fixed by #64641
Assignees
Labels
A-lint 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

@josephlr
Copy link
Contributor

josephlr commented Sep 18, 2019

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?

@jonas-schievink jonas-schievink added A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. labels Sep 18, 2019
@Centril Centril added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 19, 2019
@dhardy
Copy link
Contributor

dhardy commented Sep 20, 2019

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

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

@josephlr
Copy link
Contributor Author

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").

@cuviper
Copy link
Member

cuviper commented Sep 20, 2019

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<'_>) -> !;
}

@cuviper cuviper self-assigned this Sep 20, 2019
tmandry added a commit to tmandry/rust that referenced this issue Sep 21, 2019
Exempt extern "Rust" from improper_ctypes

It should be fine for Rust ABIs to involve any Rust type.

Fixes rust-lang#64593.
Centril added a commit to Centril/rust that referenced this issue Sep 21, 2019
Exempt extern "Rust" from improper_ctypes

It should be fine for Rust ABIs to involve any Rust type.

Fixes rust-lang#64593.
@bors bors closed this as completed in 1486b7f Sep 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint 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

Successfully merging a pull request may close this issue.

5 participants