From 5ddbd728a8766ecc4816e0f417c089b19cc91598 Mon Sep 17 00:00:00 2001 From: Noah Hellman Date: Wed, 14 Jun 2023 21:40:56 +0200 Subject: [PATCH] prepass: remove unsafe, put strings on heap actually caused spooky behavior resolves #5 --- src/lib.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9dce59c..3d0754e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -603,7 +603,7 @@ impl<'s> PrePass<'s> { ) -> Self { let mut link_definitions = Map::new(); let mut headings: Vec = Vec::new(); - let mut used_ids: Set<&str> = Set::new(); + let mut used_ids: Set = Set::new(); 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 - // 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()) - }); + used_ids.insert(id_auto.clone()); headings.push(Heading { location: e.span.start as u32, id_auto,