You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
improper_ctypes lint should check types referenced in C ABI function definitions #19834
I had to #[allow(improper_ctypes)] on a bunch of places within the libproc_macro, libstd, libpanic_abort and libpanic_unwind.
typeck currently only prohibits generics on foreign functions, so by allowing improper_ctypes on regular functions (that have extern "C"), you quickly run into something like ICE: src/librustc_lint/types.rs:858: unexpected type in foreign function: T #65035 - I added basic support for generics to the improper_ctypes lint so I could #[allow(improper_ctypes)] away the remaining errors.
The branch doesn't fail any tests at the moment. Do either of you think it's worth continuing with this and opening a PR?
Neither of these problems is a showstopper in my opinion, please continue and open a PR. Also, I have comments about both of the issues you identified and how you addressed them but it would probably best to discuss that on the PR.
Activity
tomjakubowski commentedon Dec 20, 2014
To clarify: foreign functions (
fninside anextern block) are checked. Regular functions with a C ABI are not.DanielKeep commentedon Sep 28, 2015
This is still an issue. It just came up in a Stack Overflow question, with something roughly equivalent to this:
This produces no warnings. For context, the user was trying to bind to this function from C#, which went about as well as you'd expect.
arielb1 commentedon Sep 28, 2015
@DanielKeep
Its even worse here - this is an
extern "Rust"function, and these have their own ABI.TimNN commentedon Sep 28, 2015
@arielb1 https://github.com/rust-lang/rust/blob/master/src/doc/trpl/ffi.md#calling-rust-code-from-c seems to imply that a
pub extern fn something() {}uses theCcalling convention by default.Edit: and the reference seems to agree: https://github.com/rust-lang/rust/blob/master/src/doc/reference.md#extern-functions
shepmaster commentedon Sep 16, 2016
Continues to be a problem for people new to FFI:
The OP states:
If this generated a warning, there's more of a chance people might not do this.
shepmaster commentedon Sep 16, 2016
Should we start some kind of RFC for this?
/cc @nagisa from comment
18 remaining items
shepmaster commentedon Jun 3, 2019
I have not... it's just been sitting in a tab, waiting, lonely. If someone wants to steal it, please feel free!
davidtwco commentedon Oct 5, 2019
@varkor @shepmaster I had a go at implementing the instructions in issue-19834-improper-ctypes-in-extern-C-fn, but quickly ran into problems:
#[allow(improper_ctypes)]on a bunch of places within thelibproc_macro,libstd,libpanic_abortandlibpanic_unwind.improper_ctypeson regular functions (that haveextern "C"), you quickly run into something like ICE: src/librustc_lint/types.rs:858: unexpected type in foreign function: T #65035 - I added basic support for generics to theimproper_ctypeslint so I could#[allow(improper_ctypes)]away the remaining errors.The branch doesn't fail any tests at the moment. Do either of you think it's worth continuing with this and opening a PR?
hanna-kruppe commentedon Oct 5, 2019
Neither of these problems is a showstopper in my opinion, please continue and open a PR. Also, I have comments about both of the issues you identified and how you addressed them but it would probably best to discuss that on the PR.
davidtwco commentedon Oct 5, 2019
@rkruppe opened as #65134
Rollup merge of rust-lang#72700 - davidtwco:issue-66220-improper-ctyp…
Rollup merge of rust-lang#72700 - davidtwco:issue-66220-improper-ctyp…
Rollup merge of rust-lang#72700 - davidtwco:issue-66220-improper-ctyp…
davidtwco commentedon Jul 2, 2020
Closing,
extern fns are handled in #72700.