We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ee9c7c9 commit 217e5e4Copy full SHA for 217e5e4
compiler/rustc_data_structures/src/small_c_str.rs
@@ -82,6 +82,6 @@ impl<'a> FromIterator<&'a str> for SmallCStr {
82
83
impl From<&ffi::CStr> for SmallCStr {
84
fn from(s: &ffi::CStr) -> Self {
85
- Self { data: SmallVec::from_slice(s.to_bytes()) }
+ Self { data: SmallVec::from_slice(s.to_bytes_with_nul()) }
86
}
87
compiler/rustc_data_structures/src/small_c_str/tests.rs
@@ -43,3 +43,11 @@ fn long() {
43
fn internal_nul() {
44
let _ = SmallCStr::new("abcd\0def");
45
46
+
47
+#[test]
48
+fn from_cstr() {
49
+ let c = c"foo";
50
+ let s: SmallCStr = c.into();
51
+ assert_eq!(s.len_with_nul(), 4);
52
+ assert_eq!(s.as_c_str(), c"foo");
53
+}
0 commit comments