Skip to content

Commit b2815d4

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 659211f commit b2815d4

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
@@ -364,8 +364,17 @@ lint_improper_ctypes_char_help = consider using `u32` or `libc::wchar_t` instead
364364
365365
lint_improper_ctypes_char_reason = the `char` type has no C equivalent
366366
367-
lint_improper_ctypes_cstr_help =
368-
consider passing a `*const std::ffi::c_char` instead, and use `CStr::as_ptr()`
367+
lint_improper_ctypes_cstr_help_const =
368+
consider passing a `*const std::ffi::c_char` instead, and use `CStr::as_ptr()` or `CString::as_ptr()`
369+
lint_improper_ctypes_cstr_help_mut =
370+
consider passing a `*mut std::ffi::c_char` instead, and use `CString::into_raw()` then `CString::from_raw()` or a dedicated buffer
371+
lint_improper_ctypes_cstr_help_owned =
372+
consider passing a `*const std::ffi::c_char` or `*mut std::ffi::c_char` instead,
373+
and use `CString::into_raw()` then `CString::from_raw()` or a dedicated buffer
374+
(note that `CString::into_raw()`'s output must not be `libc::free()`'d)
375+
lint_improper_ctypes_cstr_help_unknown =
376+
consider passing a `*const std::ffi::c_char` or `*mut std::ffi::c_char` instead,
377+
and use (depending on the use case) `CStr::as_ptr()`, `CString::into_raw()` then `CString::from_raw()`, or a dedicated buffer
369378
lint_improper_ctypes_cstr_reason = `CStr`/`CString` do not have a guaranteed layout
370379
371380
lint_improper_ctypes_dyn = trait objects have no C equivalent
@@ -393,6 +402,7 @@ lint_improper_ctypes_pat_reason = pattern types have no C equivalent
393402
lint_improper_ctypes_sized_ptr_to_unsafe_type =
394403
this reference (`{$ty}`) is ABI-compatible with a C pointer, but `{$inner_ty}` itself does not have a C layout
395404
405+
lint_improper_ctypes_struct_dueto = this struct/enum/union (`{$ty}`) is FFI-unsafe due to a `{$inner_ty}` field
396406
lint_improper_ctypes_slice_help = consider using a raw pointer to the slice's first element (and a length) instead
397407
398408
lint_improper_ctypes_slice_reason = slices have no C equivalent

0 commit comments

Comments
 (0)