Skip to content

Commit 249fb91

Browse files
committed
lint ImproperCTypes: more cleanups and 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 2c50f77 commit 249fb91

File tree

3 files changed

+523
-365
lines changed

3 files changed

+523
-365
lines changed

compiler/rustc_lint/messages.ftl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,17 @@ lint_improper_ctypes_char_help = consider using `u32` or `libc::wchar_t` instead
378378
379379
lint_improper_ctypes_char_reason = the `char` type has no C equivalent
380380
381-
lint_improper_ctypes_cstr_help =
382-
consider passing a `*const std::ffi::c_char` instead, and use `CStr::as_ptr()`
381+
lint_improper_ctypes_cstr_help_const =
382+
consider passing a `*const std::ffi::c_char` instead, and use `CStr::as_ptr()` or `CString::as_ptr()`
383+
lint_improper_ctypes_cstr_help_mut =
384+
consider passing a `*mut std::ffi::c_char` instead, and use `CString::into_raw()` then `CString::from_raw()` or a dedicated buffer
385+
lint_improper_ctypes_cstr_help_owned =
386+
consider passing a `*const std::ffi::c_char` or `*mut std::ffi::c_char` instead,
387+
and use `CString::into_raw()` then `CString::from_raw()` or a dedicated buffer
388+
(note that `CString::into_raw()`'s output must not be `libc::free()`'d)
389+
lint_improper_ctypes_cstr_help_unknown =
390+
consider passing a `*const std::ffi::c_char` or `*mut std::ffi::c_char` instead,
391+
and use (depending on the use case) `CStr::as_ptr()`, `CString::into_raw()` then `CString::from_raw()`, or a dedicated buffer
383392
lint_improper_ctypes_cstr_reason = `CStr`/`CString` do not have a guaranteed layout
384393
385394
lint_improper_ctypes_dyn = trait objects have no C equivalent
@@ -406,6 +415,7 @@ lint_improper_ctypes_pat_reason = pattern types have no C equivalent
406415
lint_improper_ctypes_sized_ptr_to_unsafe_type =
407416
this reference (`{$ty}`) is ABI-compatible with a C pointer, but `{$inner_ty}` itself does not have a C layout
408417
418+
lint_improper_ctypes_struct_dueto = this struct/enum/union (`{$ty}`) is FFI-unsafe due to a `{$inner_ty}` field
409419
lint_improper_ctypes_slice_help = consider using a raw pointer to the slice's first element (and a length) instead
410420
411421
lint_improper_ctypes_slice_reason = slices have no C equivalent

0 commit comments

Comments
 (0)