Skip to content

Commit 37cda44

Browse files
committed
mechanical linter changes
1 parent c50cc9e commit 37cda44

20 files changed

Lines changed: 131 additions & 143 deletions

File tree

src/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl From<CircOpt> for CircCfg {
8181
fn from(opt: CircOpt) -> Self {
8282
let field = if !opt.field.custom_modulus.is_empty() {
8383
let error =
84-
|r: &str| panic!("The field modulus '{}' is {}", &opt.field.custom_modulus, r);
84+
|r: &str| panic!("The field modulus '{}' is {}", opt.field.custom_modulus, r);
8585
let i = Integer::from_str_radix(&opt.field.custom_modulus, 10)
8686
.unwrap_or_else(|_| error("not an integer"));
8787
if i.is_probably_prime(30) == rug::integer::IsPrime::No {

src/front/datalog/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ impl<'ast> Gen<'ast> {
318318
let mut bug_in_rule_if_any = Vec::new();
319319
for cond in &rule.conds {
320320
let mut bug_conditions = Vec::new();
321-
debug!("Start case: {}", &rule.name.value);
321+
debug!("Start case: {}", rule.name.value);
322322
self.circ.enter_scope();
323323
if let Some(decls) = cond.existential.as_ref() {
324324
for d in &decls.declarations {

src/front/zsharp/mod.rs

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn const_bool_simple(t: T) -> Option<bool> {
5757
fn const_val_simple(a: T) -> Result<T, String> {
5858
match const_value_simple(&a.term) {
5959
Some(v) => Ok(T::new(a.ty, leaf_term(Op::new_const(v)))),
60-
_ => Err(format!("{} is not a constant value", &a)),
60+
_ => Err(format!("{} is not a constant value", a)),
6161
}
6262
}
6363

@@ -741,9 +741,9 @@ impl<'ast> ZGen<'ast> {
741741
let f = self
742742
.functions
743743
.get(&f_path)
744-
.ok_or_else(|| format!("No file '{:?}' attempting fn call", &f_path))?
744+
.ok_or_else(|| format!("No file '{:?}' attempting fn call", f_path))?
745745
.get(&f_name)
746-
.ok_or_else(|| format!("No function '{}' attempting fn call", &f_name))?;
746+
.ok_or_else(|| format!("No function '{}' attempting fn call", f_name))?;
747747
let arg_tys = args.iter().map(|arg| arg.type_().clone());
748748
let generics = ZGenericInf::<IS_CNST>::new(self, f, &f_path, &f_name)
749749
.unify_generic(egv, exp_ty, arg_tys)?;
@@ -780,7 +780,7 @@ impl<'ast> ZGen<'ast> {
780780
};
781781
let dur = (time::Instant::now() - before).as_millis();
782782
if dur > 50 {
783-
info!("{} ms to process {} {:?}", dur, &f_name, &f_path);
783+
info!("{} ms to process {} {:?}", dur, f_name, f_path);
784784
}
785785
ret
786786
}
@@ -802,7 +802,7 @@ impl<'ast> ZGen<'ast> {
802802
generics.remove(&gid.value).ok_or_else(|| {
803803
format!(
804804
"Failed to find generic argument {} for builtin call {}",
805-
&gid.value, &f_name,
805+
gid.value, f_name,
806806
)
807807
})
808808
})
@@ -814,15 +814,15 @@ impl<'ast> ZGen<'ast> {
814814
if f.generics.len() != generics.len() {
815815
return Err(format!(
816816
"Wrong number of generic params calling {} (got {}, expected {})",
817-
&f.id.value,
817+
f.id.value,
818818
generics.len(),
819819
f.generics.len()
820820
));
821821
}
822822
if f.parameters.len() != args.len() {
823823
return Err(format!(
824824
"Wrong nimber of arguments calling {} (got {}, expected {})",
825-
&f.id.value,
825+
f.id.value,
826826
args.len(),
827827
f.parameters.len()
828828
));
@@ -940,7 +940,7 @@ impl<'ast> ZGen<'ast> {
940940
} else {
941941
panic!(
942942
"No function '{:?}//{}' attempting const_entry_fn",
943-
&f_file, &f_name
943+
f_file, f_name
944944
)
945945
}
946946
}
@@ -952,9 +952,9 @@ impl<'ast> ZGen<'ast> {
952952
let f = self
953953
.functions
954954
.get(&f_file)
955-
.unwrap_or_else(|| panic!("No file '{:?}'", &f_file))
955+
.unwrap_or_else(|| panic!("No file '{:?}'", f_file))
956956
.get(&f_name)
957-
.unwrap_or_else(|| panic!("No function '{}'", &f_name))
957+
.unwrap_or_else(|| panic!("No function '{}'", f_name))
958958
.clone();
959959
// XXX(unimpl) tuple returns not supported
960960
assert!(f.returns.len() <= 1);
@@ -1195,7 +1195,7 @@ impl<'ast> ZGen<'ast> {
11951195
None if IS_CNST => self.cvar_lookup(&i.value).ok_or_else(|| {
11961196
format!(
11971197
"Undefined const identifier {} in {}",
1198-
&i.value,
1198+
i.value,
11991199
self.cur_path().to_string_lossy()
12001200
)
12011201
}),
@@ -1204,7 +1204,7 @@ impl<'ast> ZGen<'ast> {
12041204
.map_err(|e| format!("{e}"))?
12051205
{
12061206
Val::Term(t) => Ok(t),
1207-
_ => Err(format!("Non-Term identifier {}", &i.value)),
1207+
_ => Err(format!("Non-Term identifier {}", i.value)),
12081208
},
12091209
}
12101210
}
@@ -1338,13 +1338,7 @@ impl<'ast> ZGen<'ast> {
13381338
assert!(!p.accesses.is_empty());
13391339
let (val, accs) = if let Some(ast::Access::Call(c)) = p.accesses.first() {
13401340
let (f_path, f_name) = self.deref_import(&p.id.value);
1341-
let exp_ty = self.lhs_ty_take().and_then(|ty| {
1342-
if p.accesses.len() > 1 {
1343-
None
1344-
} else {
1345-
Some(ty)
1346-
}
1347-
});
1341+
let exp_ty = self.lhs_ty_take().filter(|_ty| p.accesses.len() <= 1);
13481342
let args = c
13491343
.arguments
13501344
.expressions
@@ -1640,7 +1634,7 @@ impl<'ast> ZGen<'ast> {
16401634
.search(&sa.id.value)
16411635
.map(|r| r.1.clone())
16421636
.ok_or_else(|| {
1643-
format!("No such member {} of struct {nm}", &sa.id.value)
1637+
format!("No such member {} of struct {nm}", sa.id.value)
16441638
}),
16451639
ty => Err(format!("Attempted member access on non-Struct type {ty}")),
16461640
},
@@ -1783,7 +1777,7 @@ impl<'ast> ZGen<'ast> {
17831777
.unwrap_or(false)
17841778
{
17851779
self.err(
1786-
format!("Constant {} clashes with import of same name", &c.id.value),
1780+
format!("Constant {} clashes with import of same name", c.id.value),
17871781
&c.span,
17881782
);
17891783
}
@@ -1816,7 +1810,7 @@ impl<'ast> ZGen<'ast> {
18161810

18171811
if let Some(ast::ArrayParamMetadata::Transcript(_)) = &c.array_metadata {
18181812
if !value.type_().is_array() {
1819-
self.err(format!("Non-array transcript {}", &c.id.value), &c.span);
1813+
self.err(format!("Non-array transcript {}", c.id.value), &c.span);
18201814
}
18211815
self.mark_array_as_transcript(&c.id.value, value.clone());
18221816
}
@@ -1829,7 +1823,7 @@ impl<'ast> ZGen<'ast> {
18291823
.insert(c.id.value.clone(), (c.ty.clone(), value))
18301824
.is_some()
18311825
{
1832-
self.err(format!("Constant {} redefined", &c.id.value), &c.span);
1826+
self.err(format!("Constant {} redefined", c.id.value), &c.span);
18331827
}
18341828
}
18351829

@@ -1869,7 +1863,7 @@ impl<'ast> ZGen<'ast> {
18691863
let (def, path) = self.get_struct_or_type(&s.id.value).ok_or_else(|| {
18701864
format!(
18711865
"No such struct {} (did you bring it into scope?)",
1872-
&s.id.value
1866+
s.id.value
18731867
)
18741868
})?;
18751869
let generics = match def {
@@ -1886,7 +1880,7 @@ impl<'ast> ZGen<'ast> {
18861880
if generics.len() != g_len {
18871881
return Err(format!(
18881882
"Struct {} is not monomorphized or wrong number of generic parameters",
1889-
&s.id.value
1883+
s.id.value
18901884
));
18911885
}
18921886
self.file_stack_push(path);
@@ -2086,7 +2080,7 @@ impl<'ast> ZGen<'ast> {
20862080
.is_some()
20872081
{
20882082
self.err(
2089-
format!("Struct {} defined over existing name", &s.id.value),
2083+
format!("Struct {} defined over existing name", s.id.value),
20902084
&s.span,
20912085
);
20922086
}
@@ -2111,7 +2105,7 @@ impl<'ast> ZGen<'ast> {
21112105
.is_some()
21122106
{
21132107
self.err(
2114-
format!("Type {} defined over existing name", &t.id.value),
2108+
format!("Type {} defined over existing name", t.id.value),
21152109
&t.span,
21162110
);
21172111
}
@@ -2132,7 +2126,7 @@ impl<'ast> ZGen<'ast> {
21322126
self.err(
21332127
format!(
21342128
"Functions must return exactly 1 value; {} returns {}",
2135-
&f_ast.id.value,
2129+
f_ast.id.value,
21362130
f_ast.returns.len(),
21372131
),
21382132
&f.span,
@@ -2164,7 +2158,7 @@ impl<'ast> ZGen<'ast> {
21642158
.insert(f.id.value.clone(), f_ast)
21652159
.is_some()
21662160
{
2167-
self.err(format!("Function {} redefined", &f.id.value), &f.span);
2161+
self.err(format!("Function {} redefined", f.id.value), &f.span);
21682162
}
21692163
}
21702164
ast::SymbolDeclaration::Import(_) => (), // already handled in visit_imports

src/front/zsharp/term.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ pub fn const_fold(t: T) -> T {
779779
pub fn const_val(a: T) -> Result<T, String> {
780780
match const_value(&a.term) {
781781
Some(v) => Ok(T::new(a.ty, const_(v))),
782-
_ => Err(format!("{} is not a constant value", &a)),
782+
_ => Err(format!("{} is not a constant value", a)),
783783
}
784784
}
785785

@@ -917,7 +917,7 @@ fn coerce_to_field(i: T) -> Result<Term, String> {
917917
match &i.ty {
918918
Ty::Uint(_) => Ok(to_dflt_f(i.term)),
919919
Ty::Field => Ok(i.term),
920-
_ => Err(format!("Cannot coerce {} to a field element", &i)),
920+
_ => Err(format!("Cannot coerce {} to a field element", i)),
921921
}
922922
}
923923

@@ -931,7 +931,7 @@ pub fn array_select(array: T, idx: T) -> Result<T, String> {
931931
let iterm = coerce_to_field(idx).unwrap();
932932
Ok(T::new(Ty::Field, term![Op::Select; array.term, iterm]))
933933
}
934-
_ => Err(format!("Cannot index {} using {}", &array.ty, &idx.ty)),
934+
_ => Err(format!("Cannot index {} using {}", array.ty, idx.ty)),
935935
}
936936
}
937937

@@ -959,7 +959,7 @@ pub fn array_store(array: T, idx: T, val: T) -> Result<T, String> {
959959
term![Op::Store; array.term, iterm, val.term],
960960
))
961961
} else {
962-
Err(format!("Cannot index {} using {}", &array.ty, &idx.ty))
962+
Err(format!("Cannot index {} using {}", array.ty, idx.ty))
963963
}
964964
}
965965

@@ -1120,7 +1120,7 @@ pub fn bit_array_le(a: T, b: T, n: usize) -> Result<T, String> {
11201120
Ok(())
11211121
}
11221122
}
1123-
_ => Err(format!("Cannot do bit-array-le on ({}, {})", &a.ty, &b.ty)),
1123+
_ => Err(format!("Cannot do bit-array-le on ({}, {})", a.ty, b.ty)),
11241124
}?;
11251125

11261126
let at = bv_from_bits(a.term, n);

src/front/zsharp/zvisit/eqtype.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn eq_array_type<'ast>(
5555
(Struct(sty), Struct(sty2)) => eq_struct_type(sty, sty2, zgen),
5656
_ => Err(ZVisitorError(format!(
5757
"array type mismatch: \n\texpected elms of type {:?}, \n\tfound {:?}",
58-
&ty.ty, &ty2.ty,
58+
ty.ty, ty2.ty,
5959
))),
6060
}
6161
}
@@ -71,7 +71,7 @@ fn eq_struct_type<'ast>(
7171
// neither ty nor ty2 is a type alias, so they are really different
7272
Err(ZVisitorError(format!(
7373
"struct type mismatch: \n\texpected {:?}, \n\tfound {:?}",
74-
&ty.id.value, &ty2.id.value,
74+
ty.id.value, ty2.id.value,
7575
)))
7676
} else {
7777
eq_type(&canon_type(ty, zgen)?, &canon_type(ty2, zgen)?, zgen)
@@ -97,7 +97,7 @@ fn canon_type<'ast>(ty: &ast::StructType<'ast>, zgen: &ZGen<'ast>) -> ZResult<as
9797
.ok_or_else(|| {
9898
ZVisitorError(format!(
9999
"eqtype: unknown struct or type alias {}",
100-
&ty.id.value
100+
ty.id.value
101101
))
102102
})
103103
}

src/front/zsharp/zvisit/zconstlitrw.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl<'ast> ZVisitorMut<'ast> for ZConstLiteralRewriter {
168168
let ty_map = if let Some(t) = to_ty.as_ref() {
169169
if let Ty::Struct(name, ty_map) = t {
170170
if name != &ise.ty.value {
171-
Err(format!("ZConstLiteralRewriter: got struct {}, expected {} visiting inline struct expression", &ise.ty.value, name))
171+
Err(format!("ZConstLiteralRewriter: got struct {}, expected {} visiting inline struct expression", ise.ty.value, name))
172172
} else {
173173
Ok(Some(ty_map.clone()))
174174
}
@@ -190,7 +190,7 @@ impl<'ast> ZVisitorMut<'ast> for ZConstLiteralRewriter {
190190
.remove(&m.id.value)
191191
.ok_or_else(|| ZVisitorError(format!(
192192
"ZConstLiteralRewriter: no member {} in struct {}, or duplicate member in inline expression",
193-
&m.id.value,
193+
m.id.value,
194194
str_name,
195195
)))
196196
.and_then(|ty| {
@@ -202,7 +202,7 @@ impl<'ast> ZVisitorMut<'ast> for ZConstLiteralRewriter {
202202
if !ty_map.is_empty() {
203203
return Err(format!(
204204
"ZConstLiteralRewriter: inline expression for struct {} has extra fields: {:?}",
205-
&ise.ty.value,
205+
ise.ty.value,
206206
ty_map.keys().collect::<Vec<_>>(),
207207
)
208208
.into());

src/front/zsharp/zvisit/zgenericinf.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<'ast, 'gen, const IS_CNST: bool> ZGenericInf<'ast, 'gen, IS_CNST> {
115115
Ty::Uint(32) => Ok(v.term),
116116
ty => Err(format!(
117117
"ZGenericInf: ConstantGenericValue for {} had type {}, expected u32",
118-
&id.value, ty
118+
id.value, ty
119119
)),
120120
}?;
121121
self.add_constraint(var, val);
@@ -135,7 +135,7 @@ impl<'ast, 'gen, const IS_CNST: bool> ZGenericInf<'ast, 'gen, IS_CNST> {
135135
(Some(rty), Some(ret)) => self.fdef_gen_ty(rty, ret),
136136
(Some(rty), None) if rty != Ty::Bool => Err(format!(
137137
"Function {} expected implicit Bool ret, but got {}",
138-
&self.fdef.id.value, rty
138+
self.fdef.id.value, rty
139139
)),
140140
(Some(_), None) => Ok(()),
141141
(None, _) => Ok(()),
@@ -155,7 +155,7 @@ impl<'ast, 'gen, const IS_CNST: bool> ZGenericInf<'ast, 'gen, IS_CNST> {
155155
{
156156
assert!(self.gens.len() == res.len());
157157
assert!(self.gens.iter().all(|g| res.contains_key(&g.value)));
158-
debug!("done (cached result for {})", &self.sfx);
158+
debug!("done (cached result for {})", self.sfx);
159159
return Ok(res);
160160
}
161161
let g_names = self
@@ -285,7 +285,7 @@ impl<'ast, 'gen, const IS_CNST: bool> ZGenericInf<'ast, 'gen, IS_CNST> {
285285
let (stdef, stpath) = self
286286
.zgen
287287
.get_struct_or_type(&def_ty.id.value)
288-
.ok_or_else(|| format!("ZGenericInf: no struct struct or type {}", &def_ty.id.value))?;
288+
.ok_or_else(|| format!("ZGenericInf: no struct struct or type {}", def_ty.id.value))?;
289289
let generics = match &stdef {
290290
Ok(strdef) => &strdef.generics[..],
291291
Err(tydef) => &tydef.generics[..],
@@ -296,7 +296,7 @@ impl<'ast, 'gen, const IS_CNST: bool> ZGenericInf<'ast, 'gen, IS_CNST> {
296296
return if def_ty.explicit_generics.is_some() {
297297
Err(format!(
298298
"Unifying generics: got explicit generics for non-generic struct type {}:\n{}",
299-
&def_ty.id.value,
299+
def_ty.id.value,
300300
span_to_string(&def_ty.span),
301301
))
302302
} else {
@@ -314,8 +314,8 @@ impl<'ast, 'gen, const IS_CNST: bool> ZGenericInf<'ast, 'gen, IS_CNST> {
314314
{
315315
return Err(format!(
316316
"Cannot infer generic values for struct {} arg to function {}\nGeneric structs in fn defns must have explicit generics (in terms of fn generic vars)",
317-
&def_ty.id.value,
318-
&self.fdef.id.value,
317+
def_ty.id.value,
318+
self.fdef.id.value,
319319
));
320320
}
321321

@@ -358,7 +358,7 @@ impl<'ast, 'gen, const IS_CNST: bool> ZGenericInf<'ast, 'gen, IS_CNST> {
358358
}
359359
Ty::Struct(aty_n, _) => Err(format!(
360360
"Type mismatch: got struct {aty_n}, decl was struct {}",
361-
&def_ty.id.value
361+
def_ty.id.value
362362
)),
363363
arg_ty => Err(format!(
364364
"Type mismatch unifying generics: got {arg_ty}, decl was Struct",
@@ -370,14 +370,14 @@ impl<'ast, 'gen, const IS_CNST: bool> ZGenericInf<'ast, 'gen, IS_CNST> {
370370
} else {
371371
return Err(format!(
372372
"ZGenericInf: missing member {} in struct {} value",
373-
&id.value, &def_ty.id.value,
373+
id.value, def_ty.id.value,
374374
));
375375
}
376376
}
377377
if !aty_map.is_empty() {
378378
return Err(format!(
379379
"ZGenericInf: struct {} value had extra members: {:?}",
380-
&def_ty.id.value,
380+
def_ty.id.value,
381381
aty_map.keys().collect::<Vec<_>>(),
382382
));
383383
}

0 commit comments

Comments
 (0)