about summary refs log tree commit diff
path: root/tests/ui/extern
diff options
context:
space:
mode:
authorFlying-Toast <38232168+Flying-Toast@users.noreply.github.com>2024-03-23 10:49:05 -0400
committer许杰友 Jieyou Xu (Joe) <jieyouxu@outlook.com>2024-08-06 13:56:59 +0000
commitb335ec9ec8d1132efee4e900a1c173efc7f4a357 (patch)
treecb0683b9e2c6672f3a079c4b54e55ac5693e9604 /tests/ui/extern
parent93ea767e2928589b74296ba85b57d80e108db712 (diff)
downloadrust-b335ec9ec8d1132efee4e900a1c173efc7f4a357.tar.gz
rust-b335ec9ec8d1132efee4e900a1c173efc7f4a357.zip
Add a special case for CStr/CString in the improper_ctypes lint
Instead of saying to "consider adding a `#[repr(C)]` or
`#[repr(transparent)]` attribute to this struct", we now tell users to
"Use `*const ffi::c_char` instead, and pass the value from
`CStr::as_ptr()`" when the type involved is a `CStr` or a `CString`.

Co-authored-by: Jieyou Xu <jieyouxu@outlook.com>
Diffstat (limited to 'tests/ui/extern')
-rw-r--r--tests/ui/extern/extern-C-non-FFI-safe-arg-ice-52334.stderr12
1 files changed, 6 insertions, 6 deletions
diff --git a/tests/ui/extern/extern-C-non-FFI-safe-arg-ice-52334.stderr b/tests/ui/extern/extern-C-non-FFI-safe-arg-ice-52334.stderr
index 83492988479..044c1ae2dd4 100644
--- a/tests/ui/extern/extern-C-non-FFI-safe-arg-ice-52334.stderr
+++ b/tests/ui/extern/extern-C-non-FFI-safe-arg-ice-52334.stderr
@@ -1,21 +1,21 @@
-warning: `extern` fn uses type `[i8 or u8 (arch dependant)]`, which is not FFI-safe
+warning: `extern` fn uses type `CStr`, which is not FFI-safe
   --> $DIR/extern-C-non-FFI-safe-arg-ice-52334.rs:7:12
    |
 LL | type Foo = extern "C" fn(::std::ffi::CStr);
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe
    |
-   = help: consider using a raw pointer instead
-   = note: slices have no C equivalent
+   = help: consider passing a `*const std::ffi::c_char` instead, and use `CStr::as_ptr()`
+   = note: `CStr`/`CString` do not have a guaranteed layout
    = note: `#[warn(improper_ctypes_definitions)]` on by default
 
-warning: `extern` block uses type `[i8 or u8 (arch dependant)]`, which is not FFI-safe
+warning: `extern` block uses type `CStr`, which is not FFI-safe
   --> $DIR/extern-C-non-FFI-safe-arg-ice-52334.rs:10:18
    |
 LL |     fn meh(blah: Foo);
    |                  ^^^ not FFI-safe
    |
-   = help: consider using a raw pointer instead
-   = note: slices have no C equivalent
+   = help: consider passing a `*const std::ffi::c_char` instead, and use `CStr::as_ptr()`
+   = note: `CStr`/`CString` do not have a guaranteed layout
    = note: `#[warn(improper_ctypes)]` on by default
 
 warning: 2 warnings emitted