Update improper_ctypes warning to add info about extern "Rust" #75030
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
The Rust ABI, while rarely the right tool for the job due to its unstable nature, has a discoverability problem when it is worth using. For example, in some embedded and/or unconventional platforms, it tends to be helpful for linkage trickery even if it is unstable.
Minimal example:
In this situation, it may be unclear to some users that not specifying an ABI for the
externblock and not specifying an ABI for the exposed#[no_mangle]function will actually lead to a mismatch of ABI due to the fact the default ABIs for these two contexts are different.The resulting warning:
This error doesn't at all allude to the actual problem causing their issue, and has (multiple times, in my experience) lead to a rather dead-in debugging experience. (Maybe it should explicitly say
externdefaults toextern "C"?)While I believe this style of:
#[no_mangle]is not good practice, it is something I have seen happen multiple times (from myself and from others asking questions) and while
extern "Rust"is not recommended, giving the user things (to google, for example) which will lead to the discovery of information about the instability of the Rust ABI and the nature, it will direct users towards the information they need to solve their problem.While I would argue
#[no_mangle]withoutexternshould raise a warning or error (as this would lead to exposing a Rust ABI function being opt-in, which better matches the unstable nature of the Rust ABI), I believe that is a significantly more controversial way to go about improving the user experience around this, hence this PR only being an update to existing warning, however I'm totally open to others' ideas on the subject.