Skip to content

Commit bca36ec

Browse files
authored
Merge pull request #140 from obeis/clippy-sugg
Apply all clippy warning
2 parents da1c0e2 + f6615dc commit bca36ec

File tree

23 files changed

+67
-82
lines changed

23 files changed

+67
-82
lines changed

crates/formality-check/src/coherence.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl Check<'_> {
140140
&a.where_clauses,
141141
&b.where_clauses,
142142
),
143-
&inverted_wc,
143+
inverted_wc,
144144
)
145145
.is_ok()
146146
}) {

crates/formality-macros/src/cast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub(crate) fn upcast_impls(s: synstructure::Structure) -> Vec<TokenStream> {
77
let num_variants = s.variants().len();
88
s.variants()
99
.iter()
10-
.filter(|v| num_variants == 1 || has_cast_attr(&v.ast().attrs))
10+
.filter(|v| num_variants == 1 || has_cast_attr(v.ast().attrs))
1111
.map(|v| upcast_to_variant(&s, v))
1212
.chain(Some(self_upcast(&s)))
1313
.collect()
@@ -46,7 +46,7 @@ pub(crate) fn downcast_impls(s: synstructure::Structure) -> Vec<TokenStream> {
4646
let num_variants = s.variants().len();
4747
s.variants()
4848
.iter()
49-
.filter(|v| num_variants == 1 || has_cast_attr(&v.ast().attrs))
49+
.filter(|v| num_variants == 1 || has_cast_attr(v.ast().attrs))
5050
.map(|v| downcast_to_variant(&s, v))
5151
.chain(Some(self_downcast(&s)))
5252
.collect()
@@ -91,5 +91,5 @@ fn downcast_to_variant(s: &synstructure::Structure, v: &VariantInfo) -> TokenStr
9191
}
9292

9393
pub(crate) fn has_cast_attr(attrs: &[Attribute]) -> bool {
94-
attrs.iter().find(|a| a.path.is_ident("cast")).is_some()
94+
attrs.iter().any(|a| a.path.is_ident("cast"))
9595
}

crates/formality-macros/src/debug.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn debug_variant(
4343

4444
// When invoked like `#[term(foo)]`, use the spec from `foo`
4545
if let Some(spec) = external_spec {
46-
return debug_variant_with_attr(variant, &spec);
46+
return debug_variant_with_attr(variant, spec);
4747
}
4848

4949
// Else, look for a `#[grammar]` attribute on the variant
@@ -58,7 +58,7 @@ fn debug_variant(
5858

5959
if variant.bindings().is_empty() {
6060
// No bindings (e.g., `Foo`) -- just parse a keyword `foo`
61-
let literal = Literal::string(&to_parse_ident(&ast.ident));
61+
let literal = Literal::string(&to_parse_ident(ast.ident));
6262
quote! {
6363
write!(fmt, #literal)?;
6464
}
@@ -79,7 +79,7 @@ fn debug_variant(
7979
quote!(#(#streams)*)
8080
} else {
8181
// Otherwise -- parse `variant(binding0, ..., bindingN)`
82-
let literal = Literal::string(&to_parse_ident(&ast.ident));
82+
let literal = Literal::string(&to_parse_ident(ast.ident));
8383
let binding_names: Vec<_> = variant.bindings().iter().map(|b| &b.binding).collect();
8484
quote! {
8585
fmt.debug_tuple(#literal)

crates/formality-macros/src/fixed_point.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl syn::parse::Parse for FixedPointArgs {
3535
while !input.is_empty() {
3636
let ident: syn::Ident = input.parse()?;
3737
let _: syn::Token!(=) = input.parse()?;
38-
if ident.to_string() == "default" {
38+
if ident == "default" {
3939
let expr: syn::Expr = input.parse()?;
4040
args.default = Some(expr);
4141
} else {
@@ -226,7 +226,7 @@ fn validate_arg_pattern(pat: &syn::Pat) -> syn::Result<(syn::Ident, Option<syn::
226226
));
227227
}
228228

229-
Ok((ident.ident.clone(), ident.mutability.clone()))
229+
Ok((ident.ident.clone(), ident.mutability))
230230
}
231231
_ => Err(syn::Error::new_spanned(
232232
pat,
@@ -245,7 +245,7 @@ fn validate_arg_ty(ty: &syn::Type) -> syn::Result<(bool, syn::Type)> {
245245
));
246246
}
247247

248-
if let Some(_) = &r.lifetime {
248+
if r.lifetime.is_some() {
249249
return Err(syn::Error::new_spanned(
250250
ty,
251251
"named lifetimes not permitted in fixed-point functions",
@@ -265,19 +265,15 @@ fn validate_arg_ty(ty: &syn::Type) -> syn::Result<(bool, syn::Type)> {
265265

266266
fn validate_ty(ty: &syn::Type) -> syn::Result<()> {
267267
match ty {
268-
syn::Type::ImplTrait(_) => {
269-
return Err(syn::Error::new_spanned(
270-
ty,
271-
"impl Trait types not allowed in fixed-point functions",
272-
));
273-
}
268+
syn::Type::ImplTrait(_) => Err(syn::Error::new_spanned(
269+
ty,
270+
"impl Trait types not allowed in fixed-point functions",
271+
)),
274272

275-
syn::Type::Reference(_) => {
276-
return Err(syn::Error::new_spanned(
277-
ty,
278-
"reference types only allowed at the top-level in fixed-point functions",
279-
));
280-
}
273+
syn::Type::Reference(_) => Err(syn::Error::new_spanned(
274+
ty,
275+
"reference types only allowed at the top-level in fixed-point functions",
276+
)),
281277

282278
_ => Ok(()),
283279
}

crates/formality-macros/src/parse.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub(crate) fn derive_parse_with_spec(
3131
let mut __results = vec![];
3232
});
3333
for variant in s.variants() {
34-
let variant_name = as_literal(&variant.ast().ident);
34+
let variant_name = as_literal(variant.ast().ident);
3535
let v = parse_variant(variant, None)?;
3636
stream.extend(quote! {
3737
__results.push({
@@ -69,7 +69,7 @@ fn parse_variant(
6969

7070
// When invoked like `#[term(foo)]`, use the spec from `foo`
7171
if let Some(spec) = external_spec {
72-
return parse_variant_with_attr(variant, &spec);
72+
return parse_variant_with_attr(variant, spec);
7373
}
7474

7575
// Else, look for a `#[grammar]` attribute on the variant
@@ -81,7 +81,7 @@ fn parse_variant(
8181

8282
if variant.bindings().is_empty() {
8383
// No bindings (e.g., `Foo`) -- just parse a keyword `foo`
84-
let literal = Literal::string(&to_parse_ident(&ast.ident));
84+
let literal = Literal::string(&to_parse_ident(ast.ident));
8585
let construct = variant.construct(|_, _| quote! {});
8686
Ok(quote! {
8787
let ((), text) = parse::expect_keyword(#literal, text)?;
@@ -97,7 +97,7 @@ fn parse_variant(
9797
})
9898
} else {
9999
// Otherwise -- parse `variant(binding0, ..., bindingN)`
100-
let literal = Literal::string(&to_parse_ident(&ast.ident));
100+
let literal = Literal::string(&to_parse_ident(ast.ident));
101101
let build: Vec<TokenStream> = parse_bindings(variant.bindings());
102102
let construct = variant.construct(field_ident);
103103
Ok(quote! {
@@ -199,7 +199,7 @@ fn lookahead(for_field: &Ident, op: Option<&FormalitySpecOp>) -> syn::Result<Lit
199199
Some(FormalitySpecOp::Keyword { .. }) | Some(FormalitySpecOp::Field { .. }) | None => {
200200
Err(syn::Error::new_spanned(
201201
for_field,
202-
format!("cannot use `*` or `,` without lookahead"),
202+
"cannot use `*` or `,` without lookahead".to_string(),
203203
))
204204
}
205205
}

crates/formality-macros/src/spec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,5 @@ fn parse_variable_binding(
129129
_ => return error(),
130130
};
131131

132-
Ok(FormalitySpecOp::Field { name, mode: mode })
132+
Ok(FormalitySpecOp::Field { name, mode })
133133
}

crates/formality-prove/src/prove/combinators.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ where
3131
let context = c1.substitution().apply(context);
3232
let a = c1.substitution().apply(&a);
3333
let b = c1.substitution().apply(&b);
34-
zip(&decls, c1.env(), &context, a, b, op)
34+
zip(decls, c1.env(), &context, a, b, op)
3535
.into_iter()
3636
.map(move |c2| c1.seq(c2))
3737
})
@@ -60,7 +60,7 @@ where
6060
.flat_map(|c1| {
6161
let context = c1.substitution().apply(context);
6262
let a_remaining = c1.substitution().apply(&a_remaining);
63-
for_all(&decls, c1.env(), &context, &a_remaining, op)
63+
for_all(decls, c1.env(), &context, &a_remaining, op)
6464
.into_iter()
6565
.map(move |c2| c1.seq(c2))
6666
})

crates/formality-prove/src/prove/env.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ impl Env {
186186

187187
let p0 = v[0];
188188
let universe_p0 = self.universe(p0);
189-
for i in 1..v.len() {
190-
assert_eq!(self.universe(v[i]).index, universe_p0.index + i);
189+
for (i, item) in v.iter().enumerate().skip(1) {
190+
assert_eq!(self.universe(item).index, universe_p0.index + i);
191191
}
192192

193193
self.variables.drain(universe_p0.index..).collect()

crates/formality-prove/src/prove/prove_wc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ judgment_fn! {
5454
(let i = i.binder.instantiate_with(&subst).unwrap())
5555
(let t = decls.trait_decl(&i.trait_ref.trait_id).binder.instantiate_with(&i.trait_ref.parameters).unwrap())
5656
(let co_assumptions = (&assumptions, &trait_ref))
57-
(prove(&decls, env, &co_assumptions, Wcs::all_eq(&trait_ref.parameters, &i.trait_ref.parameters)) => c)
58-
(prove_after(&decls, c, &co_assumptions, &i.where_clause) => c)
57+
(prove(&decls, env, co_assumptions, Wcs::all_eq(&trait_ref.parameters, &i.trait_ref.parameters)) => c)
58+
(prove_after(&decls, c, co_assumptions, &i.where_clause) => c)
5959
(prove_after(&decls, c, &assumptions, &t.where_clause) => c)
6060
----------------------------- ("positive impl")
6161
(prove_wc(decls, env, assumptions, Predicate::IsImplemented(trait_ref)) => c.pop_subst(&subst))

crates/formality-rust/src/grammar.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl Program {
3434
_ => None,
3535
})
3636
.collect();
37-
if traits.len() < 1 {
37+
if traits.is_empty() {
3838
anyhow::bail!("no trait named `{trait_id:?}`")
3939
} else if traits.len() > 1 {
4040
anyhow::bail!("multiple traits named `{trait_id:?}`")
@@ -84,9 +84,9 @@ impl Struct {
8484
Adt {
8585
id: self.id.clone(),
8686
binder: Binder::new(
87-
&vars,
87+
vars,
8888
AdtBoundData {
89-
where_clauses: where_clauses,
89+
where_clauses,
9090
variants: vec![Variant {
9191
name: VariantId::for_struct(),
9292
fields,

0 commit comments

Comments
 (0)