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!
This commit is contained in:
parent
e9013ac0e4
commit
92bf40ffe3
3 changed files with 24 additions and 8 deletions
|
@ -2118,11 +2118,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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue