diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-12-06 21:52:32 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-06 21:52:32 +0100 |
| commit | cf78a79020d4f04ceeed755db2d28ee99baad683 (patch) | |
| tree | 1a35fce725a90e9dc965df7c3107108961321bc9 /compiler/rustc_span/src | |
| parent | 1b391d4ae46e48bac50fc8817c631b2f57c8e307 (diff) | |
| parent | 92bf40ffe30832ba459e50d6f51d9e9a1cde9cd2 (diff) | |
Rollup merge of #118660 - cuviper:alloc_str, r=petrochenkov
rustc_arena: add `alloc_str` Two places called `from_utf8_unchecked` for strings from `alloc_slice`, and one's SAFETY comment said this was for lack of `alloc_str` -- so let's just add that instead!
Diffstat (limited to 'compiler/rustc_span/src')
| -rw-r--r-- | compiler/rustc_span/src/symbol.rs | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index d64f7f6db48..5c1e703837a 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -2119,11 +2119,7 @@ impl Interner { return Symbol::new(idx as u32); } - // SAFETY: we convert from `&str` to `&[u8]`, clone it into the arena, - // and immediately convert the clone back to `&[u8]`, all because there - // is no `inner.arena.alloc_str()` method. This is clearly safe. - let string: &str = - unsafe { str::from_utf8_unchecked(inner.arena.alloc_slice(string.as_bytes())) }; + let string: &str = inner.arena.alloc_str(string); // SAFETY: we can extend the arena allocation to `'static` because we // only access these while the arena is still alive. |
