Skip to content

Commit 80c37b7

Browse files
committed
lint ImproperCTypes: more major reworks
- removed special-case logic for a few cases (including the unit type, which is now only checked for in one place) - moved a lot of type-checking code in their dedicated visit_* methods - reworked FfiResult type to handle multiple diagnostics per type (currently imperfect due to type caching) - reworked the messages around CStr and CString
1 parent b3052cd commit 80c37b7

File tree

3 files changed

+386
-232
lines changed

3 files changed

+386
-232
lines changed

compiler/rustc_lint/messages.ftl

+12-2
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,17 @@ lint_improper_ctypes_char_help = consider using `u32` or `libc::wchar_t` instead
369369
370370
lint_improper_ctypes_char_reason = the `char` type has no C equivalent
371371
372-
lint_improper_ctypes_cstr_help =
373-
consider passing a `*const std::ffi::c_char` instead, and use `CStr::as_ptr()`
372+
lint_improper_ctypes_cstr_help_const =
373+
consider passing a `*const std::ffi::c_char` instead, and use `CStr::as_ptr()` or `CString::as_ptr()`
374+
lint_improper_ctypes_cstr_help_mut =
375+
consider passing a `*mut std::ffi::c_char` instead, and use `CString::into_raw()` then `CString::from_raw()` or a dedicated buffer
376+
lint_improper_ctypes_cstr_help_owned =
377+
consider passing a `*const std::ffi::c_char` or `*mut std::ffi::c_char` instead,
378+
and use `CString::into_raw()` then `CString::from_raw()` or a dedicated buffer
379+
(note that `CString::into_raw()`'s output must not be `libc::free()`'d)
380+
lint_improper_ctypes_cstr_help_unknown =
381+
consider passing a `*const std::ffi::c_char` or `*mut std::ffi::c_char` instead,
382+
and use (depending on the use case) `CStr::as_ptr()`, `CString::into_raw()` then `CString::from_raw()`, or a dedicated buffer
374383
lint_improper_ctypes_cstr_reason = `CStr`/`CString` do not have a guaranteed layout
375384
376385
lint_improper_ctypes_dyn = trait objects have no C equivalent
@@ -398,6 +407,7 @@ lint_improper_ctypes_pat_reason = pattern types have no C equivalent
398407
lint_improper_ctypes_sized_ptr_to_unsafe_type =
399408
this reference (`{$ty}`) is ABI-compatible with a C pointer, but `{$inner_ty}` itself does not have a C layout
400409
410+
lint_improper_ctypes_struct_dueto = this struct/enum/union (`{$ty}`) is FFI-unsafe due to a `{$inner_ty}` field
401411
lint_improper_ctypes_slice_help = consider using a raw pointer to the slice's first element (and a length) instead
402412
403413
lint_improper_ctypes_slice_reason = slices have no C equivalent

0 commit comments

Comments
 (0)