From 81b9ca4cfa97e41355e300b2f661a5869e5433fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Mon, 3 Feb 2020 02:39:15 +0100 Subject: [PATCH] Require identity equality for variable declarations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Variable declarations should only be considered equal if their identity is equal. In other words, just because two different variable declarations share the same name, they aren’t automatically equal. This is to support situations in which nested variable declarations shadow variable declarations of the same name at a higher level. --- src/ast.rs | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/ast.rs b/src/ast.rs index b212278..ed59891 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -70,12 +70,51 @@ impl PredicateDeclaration pub type PredicateDeclarations = std::collections::BTreeSet>; -#[derive(Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct VariableDeclaration { pub name: String, } +impl std::cmp::PartialEq for VariableDeclaration +{ + #[inline(always)] + fn eq(&self, other: &VariableDeclaration) -> bool + { + let l = self as *const VariableDeclaration; + let r = other as *const VariableDeclaration; + + l.eq(&r) + } +} + +impl std::cmp::Eq for VariableDeclaration +{ +} + +impl std::cmp::PartialOrd for VariableDeclaration +{ + #[inline(always)] + fn partial_cmp(&self, other: &VariableDeclaration) -> Option + { + let l = self as *const VariableDeclaration; + let r = other as *const VariableDeclaration; + + l.partial_cmp(&r) + } +} + +impl std::cmp::Ord for VariableDeclaration +{ + #[inline(always)] + fn cmp(&self, other: &VariableDeclaration) -> std::cmp::Ordering + { + let l = self as *const VariableDeclaration; + let r = other as *const VariableDeclaration; + + l.cmp(&r) + } +} + impl VariableDeclaration { pub fn new(name: String) -> Self