-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 "consider passing a `*const std::ffi::c_char` instead, and use `CStr::as_ptr()`" when the type involved is a `CStr` or a `CString`.
- Loading branch information
1 parent
c3b05c6
commit 2ef3825
Showing
14 changed files
with
172 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule backtrace
updated
41 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule book
updated
95 files
Submodule edition-guide
updated
11 files
Submodule reference
updated
15 files
+27 −30 | README.md | |
+0 −2 | rust-toolchain.toml | |
+4 −4 | src/attributes/codegen.md | |
+3 −4 | src/comments.md | |
+0 −15 | src/conditional-compilation.md | |
+39 −3 | src/crates-and-source-files.md | |
+6 −261 | src/expressions/literal-expr.md | |
+8 −27 | src/expressions/operator-expr.md | |
+1 −1 | src/inline-assembly.md | |
+1 −53 | src/input-format.md | |
+1 −1 | src/items/external-blocks.md | |
+2 −2 | src/lifetime-elision.md | |
+1 −2 | src/paths.md | |
+5 −20 | src/patterns.md | |
+56 −48 | src/tokens.md |
Submodule rust-by-example
updated
19 files
+2 −2 | .github/workflows/rbe.yml | |
+23 −0 | .travis.yml | |
+0 −7 | CONTRIBUTING.md | |
+1 −7 | README.md | |
+0 −257 | TRANSLATING_JA.md | |
+0 −17,231 | po/ja.po | |
+1 −1 | src/attribute.md | |
+4 −5 | src/conversion/string.md | |
+1 −2 | src/custom_types/structs.md | |
+0 −4 | src/error/multiple_error_types/wrap_error.md | |
+16 −18 | src/flow_control/while_let.md | |
+5 −5 | src/generics/new_types.md | |
+1 −1 | src/hello/print.md | |
+1 −1 | src/macros.md | |
+6 −3 | src/meta/doc.md | |
+1 −1 | src/scope/borrow.md | |
+1 −1 | src/std/str.md | |
+1 −1 | src/std_misc/process/pipe.md | |
+0 −3 | theme/index.hbs |
Submodule cargo
updated
1881 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#![crate_type = "lib"] | ||
#![deny(improper_ctypes, improper_ctypes_definitions)] | ||
|
||
use std::ffi::{CStr, CString}; | ||
|
||
extern "C" { | ||
fn take_cstr(s: CStr); | ||
//~^ ERROR `extern` block uses type `CStr`, which is not FFI-safe | ||
//~| HELP consider passing a `*const std::ffi::c_char` instead, and use `CStr::as_ptr()` | ||
fn take_cstr_ref(s: &CStr); | ||
//~^ ERROR `extern` block uses type `CStr`, which is not FFI-safe | ||
//~| HELP consider passing a `*const std::ffi::c_char` instead, and use `CStr::as_ptr()` | ||
fn take_cstring(s: CString); | ||
//~^ ERROR `extern` block uses type `CString`, which is not FFI-safe | ||
//~| HELP consider passing a `*const std::ffi::c_char` instead, and use `CStr::as_ptr()` | ||
fn take_cstring_ref(s: &CString); | ||
//~^ ERROR `extern` block uses type `CString`, which is not FFI-safe | ||
//~| HELP consider passing a `*const std::ffi::c_char` instead, and use `CStr::as_ptr()` | ||
|
||
fn no_special_help_for_mut_cstring(s: *mut CString); | ||
//~^ ERROR `extern` block uses type `CString`, which is not FFI-safe | ||
//~| HELP consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct | ||
|
||
fn no_special_help_for_mut_cstring_ref(s: &mut CString); | ||
//~^ ERROR `extern` block uses type `CString`, which is not FFI-safe | ||
//~| HELP consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct | ||
} | ||
|
||
extern "C" fn rust_take_cstr_ref(s: &CStr) {} | ||
//~^ ERROR `extern` fn uses type `CStr`, which is not FFI-safe | ||
//~| HELP consider passing a `*const std::ffi::c_char` instead, and use `CStr::as_ptr()` | ||
extern "C" fn rust_take_cstring(s: CString) {} | ||
//~^ ERROR `extern` fn uses type `CString`, which is not FFI-safe | ||
//~| HELP consider passing a `*const std::ffi::c_char` instead, and use `CStr::as_ptr()` | ||
extern "C" fn rust_no_special_help_for_mut_cstring(s: *mut CString) {} | ||
extern "C" fn rust_no_special_help_for_mut_cstring_ref(s: &mut CString) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
error: `extern` block uses type `CStr`, which is not FFI-safe | ||
--> $DIR/lint-ctypes-cstr.rs:7:21 | ||
| | ||
LL | fn take_cstr(s: CStr); | ||
| ^^^^ not FFI-safe | ||
| | ||
= 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: the lint level is defined here | ||
--> $DIR/lint-ctypes-cstr.rs:2:9 | ||
| | ||
LL | #![deny(improper_ctypes, improper_ctypes_definitions)] | ||
| ^^^^^^^^^^^^^^^ | ||
|
||
error: `extern` block uses type `CStr`, which is not FFI-safe | ||
--> $DIR/lint-ctypes-cstr.rs:10:25 | ||
| | ||
LL | fn take_cstr_ref(s: &CStr); | ||
| ^^^^^ not FFI-safe | ||
| | ||
= help: consider passing a `*const std::ffi::c_char` instead, and use `CStr::as_ptr()` | ||
= note: `CStr`/`CString` do not have a guaranteed layout | ||
|
||
error: `extern` block uses type `CString`, which is not FFI-safe | ||
--> $DIR/lint-ctypes-cstr.rs:13:24 | ||
| | ||
LL | fn take_cstring(s: CString); | ||
| ^^^^^^^ not FFI-safe | ||
| | ||
= help: consider passing a `*const std::ffi::c_char` instead, and use `CStr::as_ptr()` | ||
= note: `CStr`/`CString` do not have a guaranteed layout | ||
|
||
error: `extern` block uses type `CString`, which is not FFI-safe | ||
--> $DIR/lint-ctypes-cstr.rs:16:28 | ||
| | ||
LL | fn take_cstring_ref(s: &CString); | ||
| ^^^^^^^^ not FFI-safe | ||
| | ||
= help: consider passing a `*const std::ffi::c_char` instead, and use `CStr::as_ptr()` | ||
= note: `CStr`/`CString` do not have a guaranteed layout | ||
|
||
error: `extern` block uses type `CString`, which is not FFI-safe | ||
--> $DIR/lint-ctypes-cstr.rs:20:43 | ||
| | ||
LL | fn no_special_help_for_mut_cstring(s: *mut CString); | ||
| ^^^^^^^^^^^^ not FFI-safe | ||
| | ||
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct | ||
= note: this struct has unspecified layout | ||
|
||
error: `extern` block uses type `CString`, which is not FFI-safe | ||
--> $DIR/lint-ctypes-cstr.rs:24:47 | ||
| | ||
LL | fn no_special_help_for_mut_cstring_ref(s: &mut CString); | ||
| ^^^^^^^^^^^^ not FFI-safe | ||
| | ||
= help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct | ||
= note: this struct has unspecified layout | ||
|
||
error: `extern` fn uses type `CStr`, which is not FFI-safe | ||
--> $DIR/lint-ctypes-cstr.rs:29:37 | ||
| | ||
LL | extern "C" fn rust_take_cstr_ref(s: &CStr) {} | ||
| ^^^^^ not FFI-safe | ||
| | ||
= 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: the lint level is defined here | ||
--> $DIR/lint-ctypes-cstr.rs:2:26 | ||
| | ||
LL | #![deny(improper_ctypes, improper_ctypes_definitions)] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: `extern` fn uses type `CString`, which is not FFI-safe | ||
--> $DIR/lint-ctypes-cstr.rs:32:36 | ||
| | ||
LL | extern "C" fn rust_take_cstring(s: CString) {} | ||
| ^^^^^^^ not FFI-safe | ||
| | ||
= help: consider passing a `*const std::ffi::c_char` instead, and use `CStr::as_ptr()` | ||
= note: `CStr`/`CString` do not have a guaranteed layout | ||
|
||
error: aborting due to 8 previous errors | ||
|