Skip to content

Commit

Permalink
Merge pull request #843 from vsbogd/fix-lifetime
Browse files Browse the repository at this point in the history
Fix lifetimes
  • Loading branch information
vsbogd authored Jan 31, 2025
2 parents 14d6042 + 8db8508 commit c7d54a6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
10 changes: 5 additions & 5 deletions lib/src/atom/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,12 +1192,12 @@ pub fn atoms_are_equivalent(left: &Atom, right: &Atom) -> bool {

use std::collections::hash_map::Entry;

fn atoms_are_equivalent_with_bindings<'a, 'b: 'a>(left: &'b Atom, right: &'b Atom,
left_vars: &'a mut HashMap<&'b VariableAtom, &'b VariableAtom>,
right_vars: &'a mut HashMap<&'b VariableAtom, &'b VariableAtom>) -> bool {
fn atoms_are_equivalent_with_bindings<'a>(left: &'a Atom, right: &'a Atom,
left_vars: &mut HashMap<&'a VariableAtom, &'a VariableAtom>,
right_vars: &mut HashMap<&'a VariableAtom, &'a VariableAtom>) -> bool {

fn can_be_renamed<'a, 'b: 'a>(map: &'a mut HashMap<&'b VariableAtom, &'b VariableAtom>,
var: &'b VariableAtom, atom: &'b VariableAtom) -> bool {
fn can_be_renamed<'a>(map: &mut HashMap<&'a VariableAtom, &'a VariableAtom>,
var: &'a VariableAtom, atom: &'a VariableAtom) -> bool {
match map.entry(var) {
Entry::Occupied(entry) => *entry.get() == atom,
Entry::Vacant(entry) => {
Expand Down
28 changes: 14 additions & 14 deletions lib/src/common/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ use super::collections::{ListMap, Equality, DefaultEquality};
use std::fmt::{Debug, Display, Formatter};
use itertools::Itertools;

pub fn compare_vec_no_order<'a, T, A, B, E>(actual: A, expected: B, _cmp: E) -> VecDiff<'a, T, E>
pub fn compare_vec_no_order<T, A, B, E>(actual: A, expected: B, _cmp: E) -> VecDiff<T, E>
where
A: Iterator<Item=&'a T>,
B: Iterator<Item=&'a T>,
E: Equality<&'a T>,
A: Iterator<Item=T>,
B: Iterator<Item=T>,
E: Equality<T>,
{
let mut diff: ListMap<&T, Count, E> = ListMap::new();
let mut diff: ListMap<T, Count, E> = ListMap::new();
for i in actual {
diff.entry(&i).or_default().actual += 1;
diff.entry(i).or_default().actual += 1;
}
for i in expected {
diff.entry(&i).or_default().expected += 1;
diff.entry(i).or_default().expected += 1;
}
diff = diff.into_iter().filter(|(_v, c)| c.actual != c.expected).collect();
VecDiff{ diff }
Expand All @@ -26,8 +26,8 @@ struct Count {
expected: usize,
}

pub struct VecDiff<'a, T, E: Equality<&'a T>> {
diff: ListMap<&'a T, Count, E>,
pub struct VecDiff<T, E: Equality<T>> {
diff: ListMap<T, Count, E>,
}

struct FormatAsDebug<T: Debug>(T);
Expand All @@ -44,7 +44,7 @@ impl<T: Display> Display for FormatAsDisplay<T> {
}
}

impl<'a, T, E: Equality<&'a T>> VecDiff<'a, T, E> {
impl<T, E: Equality<T>> VecDiff<T, E> {
pub fn has_diff(&self) -> bool {
!self.diff.is_empty()
}
Expand All @@ -57,20 +57,20 @@ impl<'a, T, E: Equality<&'a T>> VecDiff<'a, T, E> {
self.as_string(FormatAsDebug)
}

fn as_string<F, I: Display>(&self, f: F) -> Option<String>
where F: Fn(&'a T) -> I
fn as_string<'a, F, I: 'a + Display>(&'a self, f: F) -> Option<String>
where F: Copy + Fn(&'a T) -> I
{
let mut diff = String::new();
if self.has_diff() {
let mut missed = self.diff.iter()
.filter(|(_v, c)| c.actual < c.expected)
.flat_map(|(v, c)| std::iter::repeat_n(v, c.expected - c.actual))
.map(|v| f(v))
.map(f)
.peekable();
let mut excessive = self.diff.iter()
.filter(|(_v, c)| c.actual > c.expected)
.flat_map(|(v, c)| std::iter::repeat_n(v, c.actual - c.expected))
.map(|v| f(v))
.map(f)
.peekable();
if missed.peek().is_some() {
diff.push_str(format!("Missed results: {}", missed.format(", ")).as_str());
Expand Down

0 comments on commit c7d54a6

Please # to comment.