Skip to content

Commit 19cb91f

Browse files
committed
use Box::leak and clean up our string leak
1 parent 2e2945f commit 19cb91f

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

src/cargo/core/interning.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,14 @@ use serde::{Serialize, Serializer};
33
use std::fmt;
44
use std::sync::RwLock;
55
use std::collections::HashSet;
6-
use std::slice;
76
use std::str;
8-
use std::mem;
97
use std::ptr;
108
use std::cmp::Ordering;
119
use std::ops::Deref;
1210
use std::hash::{Hash, Hasher};
1311

1412
pub fn leak(s: String) -> &'static str {
15-
let boxed = s.into_boxed_str();
16-
let ptr = boxed.as_ptr();
17-
let len = boxed.len();
18-
mem::forget(boxed);
19-
unsafe {
20-
let slice = slice::from_raw_parts(ptr, len);
21-
str::from_utf8_unchecked(slice)
22-
}
13+
Box::leak(s.into_boxed_str())
2314
}
2415

2516
lazy_static! {

0 commit comments

Comments
 (0)