prepass: remove unsafe, put strings on heap

actually caused spooky behavior

resolves #5
This commit is contained in:
Noah Hellman 2023-06-14 21:40:56 +02:00
parent 109e030c71
commit 5ddbd728a8

View file

@ -603,7 +603,7 @@ impl<'s> PrePass<'s> {
) -> Self { ) -> Self {
let mut link_definitions = Map::new(); let mut link_definitions = Map::new();
let mut headings: Vec<Heading> = Vec::new(); let mut headings: Vec<Heading> = Vec::new();
let mut used_ids: Set<&str> = Set::new(); let mut used_ids: Set<String> = Set::new();
let mut blocks = blocks.peekable(); let mut blocks = blocks.peekable();
@ -724,12 +724,7 @@ impl<'s> PrePass<'s> {
} }
} }
// SAFETY: used_ids is dropped before the id_auto strings in headings. even if used_ids.insert(id_auto.clone());
// the strings move due to headings reallocating, the string data on the heap
// will not move
used_ids.insert(unsafe {
std::mem::transmute::<&str, &'static str>(id_auto.as_ref())
});
headings.push(Heading { headings.push(Heading {
location: e.span.start as u32, location: e.span.start as u32,
id_auto, id_auto,