Skip to content

Commit

Permalink
use Box::leak and clean up our string leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Eh2406 committed May 10, 2018
1 parent 2e2945f commit 19cb91f
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions src/cargo/core/interning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down

0 comments on commit 19cb91f

Please sign in to comment.