Skip to content

Commit cc93bfc

Browse files
Merge pull request #30 from metadsl/fix-clippy
Fix some clippy warnings
2 parents e2f187f + 63f62a4 commit cc93bfc

File tree

2 files changed

+43
-44
lines changed

2 files changed

+43
-44
lines changed

src/conversions.rs

+34-35
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ convert_enums!(
88
egglog::ast::Literal: "{:}" => Literal {
99
Int(value: i64)
1010
i -> egglog::ast::Literal::Int(i.value),
11-
egglog::ast::Literal::Int(i) => Int { value: i.clone() };
11+
egglog::ast::Literal::Int(i) => Int { value: *i };
1212
F64(value: WrappedOrderedF64)
1313
f -> egglog::ast::Literal::F64(f.value.0),
1414
egglog::ast::Literal::F64(f) => F64 { value: WrappedOrderedF64(*f) };
@@ -27,16 +27,16 @@ convert_enums!(
2727
v -> egglog::ast::Expr::Var((&v.name).into()),
2828
egglog::ast::Expr::Var(v) => Var { name: v.to_string() };
2929
Call(name: String, args: Vec<Expr>)
30-
c -> egglog::ast::Expr::Call((&c.name).into(), (&c.args).into_iter().map(|e| e.into()).collect()),
30+
c -> egglog::ast::Expr::Call((&c.name).into(), c.args.iter().map(|e| e.into()).collect()),
3131
egglog::ast::Expr::Call(c, a) => Call {
3232
name: c.to_string(),
33-
args: a.into_iter().map(|e| e.into()).collect()
33+
args: a.iter().map(|e| e.into()).collect()
3434
}
3535
};
3636
egglog::ast::Fact: "{}" => Fact_ {
3737
Eq(exprs: Vec<Expr>)
38-
eq -> egglog::ast::Fact::Eq((&eq.exprs).into_iter().map(|e| e.into()).collect()),
39-
egglog::ast::Fact::Eq(e) => Eq { exprs: e.into_iter().map(|e| e.into()).collect() };
38+
eq -> egglog::ast::Fact::Eq(eq.exprs.iter().map(|e| e.into()).collect()),
39+
egglog::ast::Fact::Eq(e) => Eq { exprs: e.iter().map(|e| e.into()).collect() };
4040
Fact(expr: Expr)
4141
f -> egglog::ast::Fact::Fact((&f.expr).into()),
4242
egglog::ast::Fact::Fact(e) => Fact { expr: e.into() }
@@ -46,24 +46,24 @@ convert_enums!(
4646
d -> egglog::ast::Action::Let((&d.lhs).into(), (&d.rhs).into()),
4747
egglog::ast::Action::Let(n, e) => Let { lhs: n.to_string(), rhs: e.into() };
4848
Set(lhs: String, args: Vec<Expr>, rhs: Expr)
49-
s -> egglog::ast::Action::Set((&s.lhs).into(), (&s.args).into_iter().map(|e| e.into()).collect(), (&s.rhs).into()),
49+
s -> egglog::ast::Action::Set((&s.lhs).into(), s.args.iter().map(|e| e.into()).collect(), (&s.rhs).into()),
5050
egglog::ast::Action::Set(n, a, e) => Set {
5151
lhs: n.to_string(),
52-
args: a.into_iter().map(|e| e.into()).collect(),
52+
args: a.iter().map(|e| e.into()).collect(),
5353
rhs: e.into()
5454
};
5555
SetNoTrack(lhs: String, args: Vec<Expr>, rhs: Expr)
56-
s -> egglog::ast::Action::SetNoTrack((&s.lhs).into(), (&s.args).into_iter().map(|e| e.into()).collect(), (&s.rhs).into()),
56+
s -> egglog::ast::Action::SetNoTrack((&s.lhs).into(), s.args.iter().map(|e| e.into()).collect(), (&s.rhs).into()),
5757
egglog::ast::Action::SetNoTrack(n, a, e) => SetNoTrack {
5858
lhs: n.to_string(),
59-
args: a.into_iter().map(|e| e.into()).collect(),
59+
args: a.iter().map(|e| e.into()).collect(),
6060
rhs: e.into()
6161
};
6262
Delete(sym: String, args: Vec<Expr>)
63-
d -> egglog::ast::Action::Delete((&d.sym).into(), (&d.args).into_iter().map(|e| e.into()).collect()),
63+
d -> egglog::ast::Action::Delete((&d.sym).into(), d.args.iter().map(|e| e.into()).collect()),
6464
egglog::ast::Action::Delete(n, a) => Delete {
6565
sym: n.to_string(),
66-
args: a.into_iter().map(|e| e.into()).collect()
66+
args: a.iter().map(|e| e.into()).collect()
6767
};
6868
Union(lhs: Expr, rhs: Expr)
6969
u -> egglog::ast::Action::Union((&u.lhs).into(), (&u.rhs).into()),
@@ -86,8 +86,8 @@ convert_enums!(
8686
r -> egglog::ast::Schedule::Run((&r.config).into()),
8787
egglog::ast::Schedule::Run(c) => Run { config: c.into() };
8888
Sequence(schedules: Vec<Schedule>)
89-
s -> egglog::ast::Schedule::Sequence((&s.schedules).into_iter().map(|s| s.into()).collect()),
90-
egglog::ast::Schedule::Sequence(s) => Sequence { schedules: s.into_iter().map(|s| s.into()).collect() }
89+
s -> egglog::ast::Schedule::Sequence(s.schedules.iter().map(|s| s.into()).collect()),
90+
egglog::ast::Schedule::Sequence(s) => Sequence { schedules: s.iter().map(|s| s.into()).collect() }
9191
};
9292
egglog::ast::Command: "{}" => Command {
9393
SetOption(name: String, value: Expr)
@@ -102,11 +102,11 @@ convert_enums!(
102102
Datatype(name: String, variants: Vec<Variant>)
103103
d -> egglog::ast::Command::Datatype {
104104
name: (&d.name).into(),
105-
variants: (&d.variants).into_iter().map(|v| v.into()).collect()
105+
variants: d.variants.iter().map(|v| v.into()).collect()
106106
},
107107
egglog::ast::Command::Datatype {name, variants} => Datatype {
108108
name: name.to_string(),
109-
variants: variants.into_iter().map(|v| v.into()).collect()
109+
variants: variants.iter().map(|v| v.into()).collect()
110110
};
111111
Declare(name: String, sort: String)
112112
d -> egglog::ast::Command::Declare {
@@ -120,11 +120,11 @@ convert_enums!(
120120
Sort(name: String, presort_and_args: Option<(String, Vec<Expr>)>)
121121
s -> egglog::ast::Command::Sort(
122122
(&s.name).into(),
123-
(&s.presort_and_args).as_ref().map(|(p, a)| (p.into(), a.into_iter().map(|e| e.into()).collect()))
123+
s.presort_and_args.as_ref().map(|(p, a)| (p.into(), a.iter().map(|e| e.into()).collect()))
124124
),
125125
egglog::ast::Command::Sort(n, presort_and_args) => Sort {
126126
name: n.to_string(),
127-
presort_and_args: presort_and_args.as_ref().map(|(p, a)| (p.to_string(), a.into_iter().map(|e| e.into()).collect()))
127+
presort_and_args: presort_and_args.as_ref().map(|(p, a)| (p.to_string(), a.iter().map(|e| e.into()).collect()))
128128
};
129129
Function(decl: FunctionDecl)
130130
f -> egglog::ast::Command::Function((&f.decl).into()),
@@ -186,12 +186,12 @@ convert_enums!(
186186
};
187187
Calc(identifiers: Vec<IdentSort>, exprs: Vec<Expr>)
188188
c -> egglog::ast::Command::Calc(
189-
(&c.identifiers).into_iter().map(|i| i.into()).collect(),
190-
(&c.exprs).into_iter().map(|e| e.into()).collect()
189+
c.identifiers.iter().map(|i| i.into()).collect(),
190+
c.exprs.iter().map(|e| e.into()).collect()
191191
),
192192
egglog::ast::Command::Calc(identifiers, exprs) => Calc {
193-
identifiers: identifiers.into_iter().map(|i| i.into()).collect(),
194-
exprs: exprs.into_iter().map(|e| e.into()).collect()
193+
identifiers: identifiers.iter().map(|i| i.into()).collect(),
194+
exprs: exprs.iter().map(|e| e.into()).collect()
195195
};
196196
Extract(variants: usize, expr: Expr)
197197
e -> egglog::ast::Command::Extract {
@@ -203,8 +203,8 @@ convert_enums!(
203203
expr: e.into()
204204
};
205205
Check(facts: Vec<Fact_>)
206-
c -> egglog::ast::Command::Check((&c.facts).into_iter().map(|f| f.into()).collect()),
207-
egglog::ast::Command::Check(facts) => Check { facts: facts.into_iter().map(|f| f.into()).collect() };
206+
c -> egglog::ast::Command::Check(c.facts.iter().map(|f| f.into()).collect()),
207+
egglog::ast::Command::Check(facts) => Check { facts: facts.iter().map(|f| f.into()).collect() };
208208
Print(name: String, length: usize)
209209
p -> egglog::ast::Command::Print((&p.name).into(), p.length),
210210
egglog::ast::Command::Print(n, l) => Print {
@@ -217,11 +217,11 @@ convert_enums!(
217217
Output(file: String, exprs: Vec<Expr>)
218218
o -> egglog::ast::Command::Output {
219219
file: (&o.file).into(),
220-
exprs: (&o.exprs).into_iter().map(|e| e.into()).collect()
220+
exprs: o.exprs.iter().map(|e| e.into()).collect()
221221
},
222222
egglog::ast::Command::Output {file, exprs} => Output {
223223
file: file.to_string(),
224-
exprs: exprs.into_iter().map(|e| e.into()).collect()
224+
exprs: exprs.iter().map(|e| e.into()).collect()
225225
};
226226
Input(name: String, file: String)
227227
i -> egglog::ast::Command::Input {
@@ -278,34 +278,34 @@ convert_struct!(
278278
types: Vec<String>,
279279
cost: Option<usize> = None
280280
)
281-
v -> egglog::ast::Variant {name: (&v.name).into(), types: (&v.types).into_iter().map(|v| v.into()).collect(), cost: v.cost},
281+
v -> egglog::ast::Variant {name: (&v.name).into(), types: v.types.iter().map(|v| v.into()).collect(), cost: v.cost},
282282
v -> Variant {name: v.name.to_string(), types: v.types.iter().map(|v| v.to_string()).collect(), cost: v.cost};
283283
egglog::ast::Schema: "{:?}" => Schema(
284284
input: Vec<String>,
285285
output: String
286286
)
287-
s -> egglog::ast::Schema {input: (&s.input).into_iter().map(|v| v.into()).collect(), output: (&s.output).into()},
287+
s -> egglog::ast::Schema {input: s.input.iter().map(|v| v.into()).collect(), output: (&s.output).into()},
288288
s -> Schema {input: s.input.iter().map(|v| v.to_string()).collect(), output: s.output.to_string()};
289289
egglog::ast::Rule: "{}" => Rule(
290290
head: Vec<Action>,
291291
body: Vec<Fact_>
292292
)
293-
r -> egglog::ast::Rule {head: (&r.head).into_iter().map(|v| v.into()).collect(), body: (&r.body).into_iter().map(|v| v.into()).collect()},
293+
r -> egglog::ast::Rule {head: r.head.iter().map(|v| v.into()).collect(), body: r.body.iter().map(|v| v.into()).collect()},
294294
r -> Rule {head: r.head.iter().map(|v| v.into()).collect(), body: r.body.iter().map(|v| v.into()).collect()};
295295
egglog::ast::Rewrite: "{:?}" => Rewrite(
296296
lhs: Expr,
297297
rhs: Expr,
298298
conditions: Vec<Fact_> = Vec::new()
299299
)
300-
r -> egglog::ast::Rewrite {lhs: (&r.lhs).into(), rhs: (&r.rhs).into(), conditions: (&r.conditions).into_iter().map(|v| v.into()).collect()},
300+
r -> egglog::ast::Rewrite {lhs: (&r.lhs).into(), rhs: (&r.rhs).into(), conditions: r.conditions.iter().map(|v| v.into()).collect()},
301301
r -> Rewrite {lhs: (&r.lhs).into(), rhs: (&r.rhs).into(), conditions: r.conditions.iter().map(|v| v.into()).collect()};
302302
egglog::ast::RunConfig: "{:?}" => RunConfig(
303303
ruleset: String,
304304
limit: usize,
305305
until: Option<Vec<Fact_>>
306306
)
307-
r -> egglog::ast::RunConfig {ruleset: (&r.ruleset).into(), limit: r.limit, until: r.until.as_ref().map(|v| v.into_iter().map(|v| v.into()).collect())},
308-
r -> RunConfig {ruleset: r.ruleset.to_string(), limit: r.limit, until: r.until.as_ref().map(|v| v.into_iter().map(|v| v.into()).collect())};
307+
r -> egglog::ast::RunConfig {ruleset: (&r.ruleset).into(), limit: r.limit, until: r.until.as_ref().map(|v| v.iter().map(|v| v.into()).collect())},
308+
r -> RunConfig {ruleset: r.ruleset.to_string(), limit: r.limit, until: r.until.as_ref().map(|v| v.iter().map(|v| v.into()).collect())};
309309
egglog::ast::IdentSort: "{:?}" => IdentSort(
310310
ident: String,
311311
sort: String
@@ -331,7 +331,7 @@ convert_struct!(
331331

332332
impl FromPyObject<'_> for Box<Schedule> {
333333
fn extract(ob: &'_ PyAny) -> PyResult<Self> {
334-
ob.extract::<Schedule>().map(|f| Box::new(f))
334+
ob.extract::<Schedule>().map(Box::new)
335335
}
336336
}
337337

@@ -343,7 +343,7 @@ impl IntoPy<PyObject> for Box<Schedule> {
343343

344344
impl FromPyObject<'_> for Box<Command> {
345345
fn extract(ob: &'_ PyAny) -> PyResult<Self> {
346-
ob.extract::<Command>().map(|f| Box::new(f))
346+
ob.extract::<Command>().map(Box::new)
347347
}
348348
}
349349

@@ -394,8 +394,7 @@ impl FromPyObject<'_> for WrappedDuration {
394394
Ok(WrappedDuration(std::time::Duration::new(
395395
py_delta.get_days() as u64 * 24 * 60 * 60 + py_delta.get_seconds() as u64,
396396
py_delta.get_microseconds() as u32 * 1000,
397-
))
398-
.into())
397+
)))
399398
}
400399
}
401400

src/egraph.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl EGraph {
2525
#[pyo3(signature = (*, fact_directory=None, seminaive=true))]
2626
fn new(fact_directory: Option<PathBuf>, seminaive: bool) -> Self {
2727
let mut egraph = egglog::EGraph::default();
28-
egraph.fact_directory = fact_directory.clone();
28+
egraph.fact_directory = fact_directory;
2929
egraph.seminaive = seminaive;
3030
Self { egraph }
3131
}
@@ -54,21 +54,21 @@ impl EGraph {
5454
#[pyo3(signature = ())]
5555
fn extract_report(&mut self) -> Option<ExtractReport> {
5656
info!("Getting last extract report");
57-
match self.egraph.get_extract_report() {
58-
Some(report) => Some(report.into()),
59-
None => None,
60-
}
57+
self.egraph
58+
.get_extract_report()
59+
.as_ref()
60+
.map(|report| report.into())
6161
}
6262

6363
/// Gets the last run report from the EGraph, if the last command
6464
/// was a run or simplify command.
6565
#[pyo3(signature = ())]
6666
fn run_report(&mut self) -> Option<RunReport> {
6767
info!("Getting last run report");
68-
match self.egraph.get_run_report() {
69-
Some(report) => Some(report.into()),
70-
None => None,
71-
}
68+
self.egraph
69+
.get_run_report()
70+
.as_ref()
71+
.map(|report| report.into())
7272
}
7373

7474
/// Returns the EGraph as graphviz string.

0 commit comments

Comments
 (0)