Repository: mun-lang/mun (language: rust)

Issue:
Replace CStr::from_ptr(ptr).to_str() occurences with str::from_utf8_unchecked calls
**Depends on #52.**

- [x] claim this issue (assign yourself or comment below)
- [x] [setup repository on your local machine](https://github.com/mun-lang/mun) and make sure all tests pass (`cargo test`)
- [x] read our [contributing guidelines](https://github.com/mun-lang/mun/blob/master/CONTRIBUTING.md)
- [x] the Mun Runtime reads [UTF-8 strings generated by the Mun compiler](https://github.com/mun-lang/mun/blob/master/crates/mun_codegen/src/code_gen/symbols.rs) in the Mun ABI. For every such function, replace `CStr::from_ptr(ptr).to_str()` occurences with `str::from_utf8_unchecked` calls.
- [x] start a Pull Request. Set description to `closes #53`. If this is your first PR, welcome :tada: :smile:


Discussion / hints:
I would like to contribute to this issue :eyes: 

Fix patch:
diff --git a/crates/mun_abi/src/autogen_impl.rs b/crates/mun_abi/src/autogen_impl.rs
index 1b7fd2de1..62dee9125 100644
--- a/crates/mun_abi/src/autogen_impl.rs
+++ b/crates/mun_abi/src/autogen_impl.rs
@@ -3,13 +3,12 @@ use crate::prelude::*;
 use std::ffi::{c_void, CStr};
 use std::marker::{Send, Sync};
 use std::slice;
+use std::str;
 
 impl TypeInfo {
     /// Returns the type's name.
     pub fn name(&self) -> &str {
-        unsafe { CStr::from_ptr(self.name) }
-            .to_str()
-            .expect("Type name contains invalid UTF8")
+        unsafe { str::from_utf8_unchecked(CStr::from_ptr(self.name).to_bytes()) }
     }
 }
 
@@ -25,9 +24,7 @@ unsafe impl Sync for TypeInfo {}
 impl FunctionSignature {
     /// Returns the function's name.
     pub fn name(&self) -> &str {
-        unsafe { CStr::from_ptr(self.name) }
-            .to_str()
-            .expect("Function name contains invalid UTF8")
+        unsafe { str::from_utf8_unchecked(CStr::from_ptr(self.name).to_bytes()) }
     }
 
     /// Returns the function's privacy level.
@@ -59,9 +56,7 @@ unsafe impl Sync for FunctionInfo {}
 impl ModuleInfo {
     /// Returns the module's full path.
     pub fn path(&self) -> &str {
-        unsafe { CStr::from_ptr(self.path) }
-            .to_str()
-            .expect("Module path contains invalid UTF8")
+        unsafe { str::from_utf8_unchecked(CStr::from_ptr(self.path).to_bytes()) }
     }
 
     // /// Finds the type's fields that match `filter`.
@@ -180,11 +175,9 @@ impl AssemblyInfo {
             unsafe { slice::from_raw_parts(self.dependencies, self.num_dependencies as usize) }
         };
 
-        dependencies.iter().map(|d| {
-            unsafe { CStr::from_ptr(*d) }
-                .to_str()
-                .expect("dependency path contains invalid UTF8")
-        })
+        dependencies
+            .iter()
+            .map(|d| unsafe { str::from_utf8_unchecked(CStr::from_ptr(*d).to_bytes()) })
     }
 }
 


Test patch: