use Box::leak and clean up our string leak
authorEh2406 <YeomanYaacov@gmail.com>
Wed, 9 May 2018 17:24:11 +0000 (13:24 -0400)
committerEh2406 <YeomanYaacov@gmail.com>
Thu, 10 May 2018 18:04:05 +0000 (14:04 -0400)
src/cargo/core/interning.rs

index d8c18df2d8411eac8358d9dc8471a41dbeb0c475..10d44a93c6ac30d5eaf814b2b89afa53607184bb 100644 (file)
@@ -3,23 +3,14 @@ use serde::{Serialize, Serializer};
 use std::fmt;
 use std::sync::RwLock;
 use std::collections::HashSet;
-use std::slice;
 use std::str;
-use std::mem;
 use std::ptr;
 use std::cmp::Ordering;
 use std::ops::Deref;
 use std::hash::{Hash, Hasher};
 
 pub fn leak(s: String) -> &'static str {
-    let boxed = s.into_boxed_str();
-    let ptr = boxed.as_ptr();
-    let len = boxed.len();
-    mem::forget(boxed);
-    unsafe {
-        let slice = slice::from_raw_parts(ptr, len);
-        str::from_utf8_unchecked(slice)
-    }
+    Box::leak(s.into_boxed_str())
 }
 
 lazy_static! {