Skip to content

Commit

Permalink
add tests for multi-byte chars
Browse files Browse the repository at this point in the history
  • Loading branch information
y21 committed Dec 11, 2023
1 parent b394a90 commit 4fb28b0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions tests/ui/manual_c_str_literals.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ fn main() {
let _: *const _ = "foo".as_ptr(); // not a C-string
let _: *const _ = "".as_ptr();
let _: *const _ = c"foo".as_ptr().cast::<i8>();
let _ = "电脑".as_ptr();
let _ = "电脑\\".as_ptr();
let _ = c"电脑\\".as_ptr();
let _ = c"电脑".as_ptr();
let _ = c"电脑".as_ptr();

// Macro cases, don't lint:
cstr!("foo");
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/manual_c_str_literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ fn main() {
let _: *const _ = "foo".as_ptr(); // not a C-string
let _: *const _ = "".as_ptr();
let _: *const _ = b"foo\0".as_ptr().cast::<i8>();
let _ = "电脑".as_ptr();
let _ = "电脑\\".as_ptr();
let _ = "电脑\\\0".as_ptr();
let _ = "电脑\0".as_ptr();
let _ = "电脑\x00".as_ptr();

// Macro cases, don't lint:
cstr!("foo");
Expand Down
20 changes: 19 additions & 1 deletion tests/ui/manual_c_str_literals.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,23 @@ error: manually constructing a nul-terminated string
LL | let _: *const _ = b"foo\0".as_ptr().cast::<i8>();
| ^^^^^^^^ help: use a `c""` literal: `c"foo"`

error: aborting due to 10 previous errors
error: manually constructing a nul-terminated string
--> $DIR/manual_c_str_literals.rs:52:13
|
LL | let _ = "电脑\\\0".as_ptr();
| ^^^^^^^^^^ help: use a `c""` literal: `c"电脑\\"`

error: manually constructing a nul-terminated string
--> $DIR/manual_c_str_literals.rs:53:13
|
LL | let _ = "电脑\0".as_ptr();
| ^^^^^^^^ help: use a `c""` literal: `c"电脑"`

error: manually constructing a nul-terminated string
--> $DIR/manual_c_str_literals.rs:54:13
|
LL | let _ = "电脑\x00".as_ptr();
| ^^^^^^^^^^ help: use a `c""` literal: `c"电脑"`

error: aborting due to 13 previous errors

0 comments on commit 4fb28b0

Please sign in to comment.