Skip to content

Commit 0c5b2df

Browse files
committed
Fix a bunch of rust nits
1 parent c855818 commit 0c5b2df

12 files changed

Lines changed: 51 additions & 45 deletions

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
authors = ["Max Willsey <me@mwillsey.com>"]
33
categories = ["data-structures"]
44
description = "An implementation of egraphs"
5-
edition = "2018"
5+
edition = "2024"
66
keywords = ["e-graphs"]
77
license = "MIT"
88
name = "egg"

‎rust-toolchain‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.82
1+
1.94

‎src/dot.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::fmt::{self, Debug, Display, Formatter};
1111
use std::io::{Error, ErrorKind, Result, Write};
1212
use std::path::Path;
1313

14-
use crate::{egraph::EGraph, Analysis, Language};
14+
use crate::{Analysis, Language, egraph::EGraph};
1515

1616
/**
1717
A wrapper for an [`EGraph`] that can output [GraphViz] for

‎src/egraph.rs‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ impl<L: Language, N: Analysis<L>> EGraph<L, N> {
233233
/// Make a copy of the egraph with the same nodes, but no unions between them.
234234
pub fn copy_without_unions(&self, analysis: N) -> Self {
235235
if self.explain.is_none() {
236-
panic!("Use runner.with_explanations_enabled() or egraph.with_explanations_enabled() before running to get a copied egraph without unions");
236+
panic!(
237+
"Use runner.with_explanations_enabled() or egraph.with_explanations_enabled() before running to get a copied egraph without unions"
238+
);
237239
}
238240
let mut egraph = Self::new(analysis);
239241
for node in &self.nodes {
@@ -430,7 +432,9 @@ impl<L: Language, N: Analysis<L>> EGraph<L, N> {
430432
if let Some(explain) = &self.explain {
431433
explain.get_union_equalities()
432434
} else {
433-
panic!("Use runner.with_explanations_enabled() or egraph.with_explanations_enabled() before running to get union equalities");
435+
panic!(
436+
"Use runner.with_explanations_enabled() or egraph.with_explanations_enabled() before running to get union equalities"
437+
);
434438
}
435439
}
436440

@@ -453,7 +457,9 @@ impl<L: Language, N: Analysis<L>> EGraph<L, N> {
453457
.with_nodes(&self.nodes)
454458
.get_num_congr::<N>(&self.classes, &self.unionfind)
455459
} else {
456-
panic!("Use runner.with_explanations_enabled() or egraph.with_explanations_enabled() before running to get explanations.")
460+
panic!(
461+
"Use runner.with_explanations_enabled() or egraph.with_explanations_enabled() before running to get explanations."
462+
)
457463
}
458464
}
459465

@@ -462,7 +468,9 @@ impl<L: Language, N: Analysis<L>> EGraph<L, N> {
462468
if let Some(explain) = &mut self.explain {
463469
explain.with_nodes(&self.nodes).get_num_nodes()
464470
} else {
465-
panic!("Use runner.with_explanations_enabled() or egraph.with_explanations_enabled() before running to get explanations.")
471+
panic!(
472+
"Use runner.with_explanations_enabled() or egraph.with_explanations_enabled() before running to get explanations."
473+
)
466474
}
467475
}
468476

@@ -505,7 +513,9 @@ impl<L: Language, N: Analysis<L>> EGraph<L, N> {
505513
&self.classes,
506514
)
507515
} else {
508-
panic!("Use runner.with_explanations_enabled() or egraph.with_explanations_enabled() before running to get explanations.")
516+
panic!(
517+
"Use runner.with_explanations_enabled() or egraph.with_explanations_enabled() before running to get explanations."
518+
)
509519
}
510520
}
511521

@@ -533,7 +543,9 @@ impl<L: Language, N: Analysis<L>> EGraph<L, N> {
533543
&self.classes,
534544
)
535545
} else {
536-
panic!("Use runner.with_explanations_enabled() or egraph.with_explanations_enabled() before running to get explanations.");
546+
panic!(
547+
"Use runner.with_explanations_enabled() or egraph.with_explanations_enabled() before running to get explanations."
548+
);
537549
}
538550
}
539551

@@ -565,7 +577,7 @@ impl<L: Language, N: Analysis<L>> EGraph<L, N> {
565577
}
566578

567579
/// Creates a [`Dot`] to visualize this egraph. See [`Dot`].
568-
pub fn dot(&self) -> Dot<L, N> {
580+
pub fn dot(&self) -> Dot<'_, L, N> {
569581
Dot {
570582
egraph: self,
571583
config: vec![],

‎src/explain.rs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#![allow(clippy::only_used_in_recursion)]
22
use crate::Symbol;
33
use crate::{
4-
util::pretty_print, Analysis, EClass, ENodeOrVar, FromOp, HashMap, HashSet, Id, Language,
5-
PatternAst, RecExpr, Rewrite, UnionFind, Var,
4+
Analysis, EClass, ENodeOrVar, FromOp, HashMap, HashSet, Id, Language, PatternAst, RecExpr,
5+
Rewrite, UnionFind, Var, util::pretty_print,
66
};
77

88
use std::cmp::Ordering;
@@ -842,7 +842,8 @@ impl<L: Language> FlatTerm<L> {
842842
if existing != &self {
843843
panic!(
844844
"Invalid proof: binding for variable {:?} does not match between {:?} \n and \n {:?}",
845-
var, existing, self);
845+
var, existing, self
846+
);
846847
}
847848
} else {
848849
bindings.insert(*var, self);

‎src/extract.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::cmp::Ordering;
22
use std::fmt::Debug;
33

4-
use crate::util::{hashmap_with_capacity, HashMap};
4+
use crate::util::{HashMap, hashmap_with_capacity};
55
use crate::{Analysis, EClass, EGraph, Id, Language, RecExpr};
66

77
/** Extracting a single [`RecExpr`] from an [`EGraph`].

‎src/language.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,8 @@ impl<L: Language> RecExpr<L> {
500500
pub fn items_mut(
501501
&mut self,
502502
) -> impl ExactSizeIterator<Item = (Id, &mut L)> + DoubleEndedIterator {
503-
self.ids().zip(self)
503+
let ids = (0..self.len()).map(Id::from);
504+
ids.zip(self.iter_mut())
504505
}
505506

506507
/// Checks if this expr is a DAG, i.e. doesn't have any back edges

‎src/lp_extract.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use good_lp::{
2-
default_solver, solvers::WithTimeLimit, variable, variables, Expression, Solution,
3-
SolutionStatus, Solver, SolverModel, Variable,
2+
Expression, Solution, SolutionStatus, Solver, SolverModel, Variable, default_solver,
3+
solvers::WithTimeLimit, variable, variables,
44
};
55
use std::time::Instant;
66

@@ -69,7 +69,7 @@ impl<L: Language, N: Analysis<L>> LpCostFunction<L, N> for AstSize {
6969
/// good_lp = { version = "1", features = ["coin_cbc"] } # or highs, microlp, etc.
7070
/// ```
7171
///
72-
/// See the (`good_lp` documentation)[https://docs.rs/good_lp/1/good_lp/solvers/index.html]
72+
/// See the [`good_lp` documentation](https://docs.rs/good_lp/1/good_lp/solvers/index.html)
7373
///
7474
/// At run time, select the solver by calling [`Self::solve_with`], [`Self::solve_multiple_with`], [`Self::solve_with_timeout`], or [`Self::solve_multiple_with_timeout`]
7575
/// and passing one of the enabled `good_lp` solver implementations.
@@ -93,7 +93,7 @@ impl<L: Language, N: Analysis<L>> LpCostFunction<L, N> for AstSize {
9393
/// let rec = LpExtractor::new(egraph, AstSize)
9494
/// .solve_with(root, highs);
9595
/// # let _ = rec;
96-
/// ```
96+
/// ```
9797
///
9898
#[cfg_attr(docsrs, doc(cfg(feature = "lp")))]
9999
pub struct LpExtractor<'a, L: Language, N: Analysis<L>> {
@@ -304,7 +304,7 @@ where
304304
(expr, root_idxs)
305305
}
306306

307-
/// Like [`solve_multiple`], but lets the caller provide a `good_lp` solver backend.
307+
/// Like [`LpExtractor::solve_multiple`], but lets the caller provide a `good_lp` solver backend.
308308
/// Example: `solve_multiple_with(roots, good_lp::highs)`.
309309
pub fn solve_multiple_with<S: Solver>(
310310
&mut self,
@@ -336,7 +336,7 @@ where
336336
self.extract_solution::<S>(solution, &vars, roots)
337337
}
338338

339-
/// Like [`solve_multiple_with`], but lets the caller provide a time limit for the 'good_lp' solver in seconds.
339+
/// Like [`LpExtractor::solve_multiple_with`], but lets the caller provide a time limit for the 'good_lp' solver in seconds.
340340
/// Example: `solve_multiple_with_timeout(roots, good_lp::highs, 600.0)`.
341341
pub fn solve_multiple_with_timeout<S: Solver>(
342342
&mut self,

‎src/machine.rs‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,7 @@ impl<L: Language> Program<L> {
334334
.collect();
335335
matches.push(Subst { vec: subst_vec });
336336
limit -= 1;
337-
if limit != 0 {
338-
Ok(())
339-
} else {
340-
Err(())
341-
}
337+
if limit != 0 { Ok(()) } else { Err(()) }
342338
},
343339
)
344340
.unwrap_or_default();

‎src/multipattern.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<L: Language, A: Analysis<L>> Searcher<L, A> for MultiPattern<L> {
106106
egraph: &EGraph<L, A>,
107107
eclass: Id,
108108
limit: usize,
109-
) -> Option<SearchMatches<L>> {
109+
) -> Option<SearchMatches<'_, L>> {
110110
match self.asts.as_slice() {
111111
[] => panic!("empty multipattern"),
112112
[(_var, pat), ..] => {

0 commit comments

Comments
 (0)