Skip to content

Commit bf70389

Browse files
author
Xing Xue
committed
Not to cast to i8 for c_char.
1 parent 0cbd33d commit bf70389

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

ctest-next/templates/test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ mod generated_tests {
5656
let val = {{ ident }};
5757
unsafe {
5858
let ptr = *__test_const_{{ ident }}();
59-
// c_char can be i8 or u8, so just cast to i8.
60-
let val = CStr::from_ptr(ptr.cast::<i8>());
59+
let val = unsafe {CStr::from_ptr(ptr)};
6160
let val = val.to_str().expect("const {{ ident }} not utf8");
6261
let c = ::std::ffi::CStr::from_ptr(ptr as *const _);
6362
let c = c.to_str().expect("const {{ ident }} not utf8");

ctest-next/tests/input/simple.out.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ mod generated_tests {
4949
let val = A;
5050
unsafe {
5151
let ptr = *__test_const_A();
52-
// c_char can be i8 or u8, so just cast to i8.
53-
let val = CStr::from_ptr(ptr.cast::<i8>());
52+
let val = unsafe {CStr::from_ptr(ptr)};
5453
let val = val.to_str().expect("const A not utf8");
5554
let c = ::std::ffi::CStr::from_ptr(ptr as *const _);
5655
let c = c.to_str().expect("const A not utf8");

0 commit comments

Comments
 (0)