Skip to content

Commit 0ca2245

Browse files
committed
string leek is stable
1 parent e3b3ed8 commit 0ca2245

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/cargo/util/interning.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ use std::str;
1212
use std::sync::Mutex;
1313
use std::sync::OnceLock;
1414

15-
fn leak(s: String) -> &'static str {
16-
Box::leak(s.into_boxed_str())
17-
}
18-
1915
static STRING_CACHE: OnceLock<Mutex<HashSet<&'static str>>> = OnceLock::new();
2016

2117
#[derive(Clone, Copy)]
@@ -64,11 +60,11 @@ impl Eq for InternedString {}
6460
impl InternedString {
6561
pub fn new(str: &str) -> InternedString {
6662
let mut cache = STRING_CACHE
67-
.get_or_init(|| Default::default())
63+
.get_or_init(Default::default)
6864
.lock()
6965
.unwrap();
7066
let s = cache.get(str).cloned().unwrap_or_else(|| {
71-
let s = leak(str.to_string());
67+
let s = str.to_string().leak();
7268
cache.insert(s);
7369
s
7470
});

0 commit comments

Comments
 (0)