Make StrongRuleNode::downgrade be unsafe

This commit is contained in:
Anthony Ramine 2020-04-16 16:24:19 +02:00
parent fb28ce6bbe
commit bc4e2942bf

View file

@ -367,8 +367,8 @@ impl StrongRuleNode {
StrongRuleNode { p } StrongRuleNode { p }
} }
fn downgrade(&self) -> WeakRuleNode { unsafe fn downgrade(&self) -> WeakRuleNode {
unsafe { WeakRuleNode::from_ptr(self.p) } WeakRuleNode::from_ptr(self.p)
} }
/// Get the parent rule node of this rule node. /// Get the parent rule node of this rule node.
@ -404,10 +404,10 @@ impl StrongRuleNode {
key, key,
|node| unsafe { (*node.ptr()).key() }, |node| unsafe { (*node.ptr()).key() },
move || { move || {
let root = root.downgrade(); let root = unsafe { root.downgrade() };
let strong = let strong =
StrongRuleNode::new(Box::new(RuleNode::new(root, self.clone(), source, level))); StrongRuleNode::new(Box::new(RuleNode::new(root, self.clone(), source, level)));
let weak = strong.downgrade(); let weak = unsafe { strong.downgrade() };
mem::forget(strong); mem::forget(strong);
weak weak
}, },