Skip to content

Commit 7f97a92

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 2dcfd51 commit 7f97a92

File tree

9 files changed

+519
-262
lines changed

9 files changed

+519
-262
lines changed

compiler/rustc_lint/messages.ftl

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

0 commit comments

Comments
 (0)