diff options
author | Wilfred Hughes <me@wilfred.me.uk> | 2022-04-24 21:49:58 -0700 |
---|---|---|
committer | Wilfred Hughes <me@wilfred.me.uk> | 2022-04-24 21:49:58 -0700 |
commit | f64a20a7bde82e87a104c4f1627bb306ec682553 (patch) | |
tree | eaf0ebbeb9a8454dfe7f424aa3da7b8e57e6b8ed | |
parent | 6a404f51a836d24aac294ffb778822612e12aab9 (diff) |
WIP remove Syntax::PartialEqremove_eq_on_syntax
-rw-r--r-- | src/changes.rs | 2 | ||||
-rw-r--r-- | src/dijkstra.rs | 19 | ||||
-rw-r--r-- | src/graph.rs | 2 | ||||
-rw-r--r-- | src/sliders.rs | 21 | ||||
-rw-r--r-- | src/syntax.rs | 23 |
5 files changed, 35 insertions, 32 deletions
diff --git a/src/changes.rs b/src/changes.rs index 1176971d5..d1a9aa62d 100644 --- a/src/changes.rs +++ b/src/changes.rs @@ -4,7 +4,7 @@ use rustc_hash::FxHashMap; use crate::syntax::Syntax; -#[derive(PartialEq, Eq, Clone, Copy)] +#[derive(Clone, Copy)] pub enum ChangeKind<'a> { Unchanged(&'a Syntax<'a>), ReplacedComment(&'a Syntax<'a>, &'a Syntax<'a>), diff --git a/src/dijkstra.rs b/src/dijkstra.rs index 289acf0ad..4cc35d340 100644 --- a/src/dijkstra.rs +++ b/src/dijkstra.rs @@ -566,8 +566,18 @@ mod tests { let mut change_map = ChangeMap::default(); mark_syntax(Some(lhs), Some(rhs), &mut change_map); - assert_eq!(change_map.get(lhs), Some(ChangeKind::Unchanged(rhs))); - assert_eq!(change_map.get(rhs), Some(ChangeKind::Unchanged(lhs))); + match change_map.get(lhs) { + Some(ChangeKind::Unchanged(rhs)) => { + assert_eq!(lhs.content_id(), rhs.content_id()); + } + _ => assert!(false), + } + match change_map.get(rhs) { + Some(ChangeKind::Unchanged(lhs)) => { + assert_eq!(lhs.content_id(), rhs.content_id()); + } + _ => assert!(false), + } } #[test] @@ -579,7 +589,8 @@ mod tests { let mut change_map = ChangeMap::default(); mark_syntax(Some(lhs), Some(rhs), &mut change_map); - assert_eq!(change_map.get(lhs), Some(ChangeKind::Novel)); - assert_eq!(change_map.get(rhs), Some(ChangeKind::Novel)); + + assert!(matches!(change_map.get(lhs), Some(ChangeKind::Novel))); + assert!(matches!(change_map.get(rhs), Some(ChangeKind::Novel))); } } diff --git a/src/graph.rs b/src/graph.rs index 81440a5fb..87e1f66f7 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -400,7 +400,7 @@ pub fn neighbours<'a>(v: &Vertex<'a>, buf: &mut [Option<(Edge, Vertex<'a>)>]) { } if let (Some(lhs_syntax), Some(rhs_syntax)) = (&v.lhs_syntax, &v.rhs_syntax) { - if lhs_syntax == rhs_syntax { + if lhs_syntax.content_id() == rhs_syntax.content_id() { let depth_difference = (lhs_syntax.num_ancestors() as i32 - rhs_syntax.num_ancestors() as i32) .abs() as u32; diff --git a/src/sliders.rs b/src/sliders.rs index 131cf3e58..a82b7a52d 100644 --- a/src/sliders.rs +++ b/src/sliders.rs @@ -529,8 +529,10 @@ mod tests { change_map.insert(lhs[2], Novel); fix_all_sliders(guess_language::Language::EmacsLisp, &lhs, &mut change_map); - assert_eq!(change_map.get(lhs[0]), Some(Novel)); - assert_eq!(change_map.get(lhs[1]), Some(Novel)); + + assert!(matches!(change_map.get(lhs[0]), Some(Novel))); + assert!(matches!(change_map.get(lhs[1]), Some(Novel))); + assert_eq!(change_map.get(lhs[2]), Some(Unchanged(rhs[0]))); assert_eq!(change_map.get(rhs[0]), Some(Unchanged(lhs[2]))); } @@ -581,9 +583,11 @@ mod tests { assert_eq!(change_map.get(rhs[0]), Some(Unchanged(lhs[0]))); assert_eq!(change_map.get(lhs[0]), Some(Unchanged(rhs[0]))); - assert_eq!(change_map.get(lhs[1]), Some(Novel)); - assert_eq!(change_map.get(lhs[2]), Some(Novel)); + + assert!(matches!(change_map.get(lhs[1]), Some(Novel))); + assert!(matches!(change_map.get(lhs[2]), Some(Novel))); } + #[test] fn test_slider_two_steps() { let arena = Arena::new(); @@ -601,9 +605,12 @@ mod tests { change_map.insert(rhs[4], Novel); fix_all_sliders(guess_language::Language::EmacsLisp, &rhs, &mut change_map); - assert_eq!(change_map.get(rhs[0]), Some(Novel)); - assert_eq!(change_map.get(rhs[1]), Some(Novel)); - assert_eq!(change_map.get(rhs[2]), Some(Novel)); + + assert!(matches!(change_map.get(rhs[0]), Some(Novel))); + assert!(matches!(change_map.get(rhs[1]), Some(Novel))); + assert!(matches!(change_map.get(rhs[2]), Some(Novel))); + + assert_eq!(change_map.get(rhs[3]), Some(Unchanged(rhs[0]))); } } diff --git a/src/syntax.rs b/src/syntax.rs index 13d4be308..63b58e77c 100644 --- a/src/syntax.rs +++ b/src/syntax.rs @@ -2,13 +2,7 @@ #![allow(clippy::mutable_key_type)] // Hash for Syntax doesn't use mutable fields. -use std::{ - cell::Cell, - collections::HashMap, - env, fmt, - hash::Hash, - num::NonZeroU32, -}; +use std::{cell::Cell, collections::HashMap, env, fmt, hash::Hash, num::NonZeroU32}; use typed_arena::Arena; use crate::{ @@ -503,15 +497,6 @@ fn set_prev_is_contiguous<'a>(roots: &[&Syntax<'a>]) { } } -impl<'a> PartialEq for Syntax<'a> { - fn eq(&self, other: &Self) -> bool { - debug_assert!(self.content_id() > 0); - debug_assert!(other.content_id() > 0); - self.content_id() == other.content_id() - } -} -impl<'a> Eq for Syntax<'a> {} - #[derive(PartialEq, Eq, Debug, Clone, Copy, Hash)] pub enum AtomKind { Normal, @@ -879,7 +864,7 @@ mod tests { let atom = Syntax::new_atom(&arena, pos, "foo", AtomKind::Normal); init_all_info(&[comment], &[atom]); - assert_ne!(comment, atom); + assert_ne!(comment.content_id(), atom.content_id()); } /// Ignore the syntax highighting kind when comparing @@ -899,7 +884,7 @@ mod tests { let atom = Syntax::new_atom(&arena, pos, "foo", AtomKind::Normal); init_all_info(&[type_atom], &[atom]); - assert_eq!(type_atom, atom); + assert_eq!(type_atom.content_id(), atom.content_id()); } #[test] @@ -953,7 +938,7 @@ mod tests { let y = Syntax::new_atom(&arena, pos, "foo\n bar", AtomKind::Comment); init_all_info(&[x], &[y]); - assert_eq!(x, y); + assert_eq!(x.content_id(), y.content_id()); } #[test] |