Skip to content

Commit 220d8e4

Browse files
committed
chore: fmt
1 parent 42f67bc commit 220d8e4

File tree

13 files changed

+170
-143
lines changed

13 files changed

+170
-143
lines changed

.cspell.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ version: "0.2"
22
words:
33
- clippy
44
- direnv
5+
- nixos
6+
- nixpkgs
7+
- pkgs
8+
- taplo

.taplo.toml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,28 @@ exclude = ["target/*"]
22
include = ["**/*.toml"]
33

44
[formatting]
5-
column_width = 100
5+
column_width = 110
66

77
[[rule]]
88
include = ["**/Cargo.toml"]
9-
keys = ["dependencies", "*-dependencies"]
10-
11-
[rule.formatting]
12-
reorder_keys = true
9+
keys = [
10+
"dependencies",
11+
"*-dependencies",
12+
"workspace.dependencies",
13+
"workspace.*-dependencies",
14+
"target.*.dependencies",
15+
"target.*.*-dependencies",
16+
]
17+
formatting.reorder_keys = true
1318

1419
[[rule]]
1520
include = ["**/Cargo.toml"]
16-
keys = ["dependencies.*", "*-dependencies.*"]
17-
18-
[rule.formatting]
19-
reorder_keys = false
21+
keys = [
22+
"dependencies.*",
23+
"*-dependencies.*",
24+
"workspace.dependencies.*",
25+
"workspace.*-dependencies.*",
26+
"target.*.dependencies",
27+
"target.*.*-dependencies",
28+
]
29+
formatting.reorder_keys = false

examples/library.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use contracts::*;
6-
75
use std::collections::HashSet;
86

7+
use contracts::*;
8+
99
pub struct Library {
1010
available: HashSet<String>,
1111
lent: HashSet<String>,

flake.lock

Lines changed: 85 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/implementation/codegen.rs

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@
44

55
use proc_macro2::{Ident, Span, TokenStream};
66
use quote::ToTokens;
7-
use syn::{
8-
spanned::Spanned, visit_mut as visitor, Attribute, Expr, ExprCall,
9-
ReturnType,
10-
};
7+
use syn::{spanned::Spanned, visit_mut as visitor, Attribute, Expr, ExprCall, ReturnType};
118

12-
use crate::implementation::{
13-
Contract, ContractMode, ContractType, FuncWithContracts,
14-
};
9+
use crate::implementation::{Contract, ContractMode, ContractType, FuncWithContracts};
1510

1611
/// Substitution for `old()` expressions.
1712
pub(crate) struct OldExpr {
@@ -222,9 +217,7 @@ pub(crate) fn generate(
222217
let pre: proc_macro2::TokenStream = func
223218
.contracts
224219
.iter()
225-
.filter(|c| {
226-
c.ty == ContractType::Requires || c.ty == ContractType::Invariant
227-
})
220+
.filter(|c| c.ty == ContractType::Requires || c.ty == ContractType::Invariant)
228221
.flat_map(|c| {
229222
let desc = if let Some(desc) = c.desc.as_ref() {
230223
format!(
@@ -237,8 +230,10 @@ pub(crate) fn generate(
237230
format!("{} of {} violated", c.ty.message_name(), func_name)
238231
};
239232

240-
c.assertions.iter().zip(c.streams.iter()).map(
241-
move |(expr, display)| {
233+
c.assertions
234+
.iter()
235+
.zip(c.streams.iter())
236+
.map(move |(expr, display)| {
242237
let mode = c.mode.final_mode();
243238

244239
make_assertion(
@@ -248,8 +243,7 @@ pub(crate) fn generate(
248243
expr,
249244
&desc.clone(),
250245
)
251-
},
252-
)
246+
})
253247
})
254248
.collect();
255249

@@ -260,9 +254,7 @@ pub(crate) fn generate(
260254
let post: proc_macro2::TokenStream = func
261255
.contracts
262256
.iter()
263-
.filter(|c| {
264-
c.ty == ContractType::Ensures || c.ty == ContractType::Invariant
265-
})
257+
.filter(|c| c.ty == ContractType::Ensures || c.ty == ContractType::Invariant)
266258
.flat_map(|c| {
267259
let desc = if let Some(desc) = c.desc.as_ref() {
268260
format!(
@@ -275,8 +267,10 @@ pub(crate) fn generate(
275267
format!("{} of {} violated", c.ty.message_name(), func_name)
276268
};
277269

278-
c.assertions.iter().zip(c.streams.iter()).map(
279-
move |(expr, display)| {
270+
c.assertions
271+
.iter()
272+
.zip(c.streams.iter())
273+
.map(move |(expr, display)| {
280274
let mode = c.mode.final_mode();
281275

282276
make_assertion(
@@ -286,8 +280,7 @@ pub(crate) fn generate(
286280
expr,
287281
&desc.clone(),
288282
)
289-
},
290-
)
283+
})
291284
})
292285
.collect();
293286

@@ -414,8 +407,7 @@ fn create_body_closure(func: &syn::ItemFn) -> TokenStream {
414407
path: syn::Path::from(syn::Ident::new("Self", rcv.span())),
415408
}));
416409

417-
let ty = if let Some((and_token, ref lifetime)) = rcv.reference
418-
{
410+
let ty = if let Some((and_token, ref lifetime)) = rcv.reference {
419411
Box::new(syn::Type::Reference(syn::TypeReference {
420412
and_token,
421413
lifetime: lifetime.clone(),
@@ -463,8 +455,7 @@ fn create_body_closure(func: &syn::ItemFn) -> TokenStream {
463455

464456
match &func.sig.inputs[0] {
465457
syn::FnArg::Receiver(receiver) => {
466-
arg_names
467-
.push(syn::Ident::new("self", receiver.self_token.span()));
458+
arg_names.push(syn::Ident::new("self", receiver.self_token.span()));
468459
}
469460
syn::FnArg::Typed(pat) => {
470461
if let syn::Pat::Ident(ident) = &*pat.pat {
@@ -500,9 +491,7 @@ fn create_body_closure(func: &syn::ItemFn) -> TokenStream {
500491

501492
// Any function argument identifier starting with '_' signals
502493
// that the binding will not be used.
503-
if !ident_str.starts_with('_')
504-
|| ident_str.starts_with("__")
505-
{
494+
if !ident_str.starts_with('_') || ident_str.starts_with("__") {
506495
arg_names.push(ident.ident.clone());
507496
closure_args.push(arg.clone());
508497
}

src/implementation/doc.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use crate::implementation::{Contract, ContractMode};
6-
use proc_macro2::Span;
7-
use proc_macro2::TokenStream;
5+
use proc_macro2::{Span, TokenStream};
86
use syn::{parse::Parser, Attribute};
97

8+
use crate::implementation::{Contract, ContractMode};
9+
1010
pub(crate) fn generate_attributes(contracts: &[Contract]) -> Vec<Attribute> {
1111
let mut attrs = vec![];
1212

@@ -15,8 +15,7 @@ pub(crate) fn generate_attributes(contracts: &[Contract]) -> Vec<Attribute> {
1515

1616
let content_str = syn::LitStr::new(content, span);
1717

18-
let toks: TokenStream =
19-
quote::quote_spanned!( span=> #[doc = #content_str] );
18+
let toks: TokenStream = quote::quote_spanned!( span=> #[doc = #content_str] );
2019

2120
let parser = Attribute::parse_outer;
2221

@@ -53,13 +52,8 @@ pub(crate) fn generate_attributes(contracts: &[Contract]) -> Vec<Attribute> {
5352

5453
attrs.push(make_attribute(&header_txt));
5554

56-
for (_assert, stream) in
57-
contract.assertions.iter().zip(contract.streams.iter())
58-
{
59-
attrs.push(make_attribute(&format!(
60-
" - `{}`",
61-
print_stream(stream)
62-
)));
55+
for (_assert, stream) in contract.assertions.iter().zip(contract.streams.iter()) {
56+
attrs.push(make_attribute(&format!(" - `{}`", print_stream(stream))));
6357
}
6458

6559
attrs.push(make_attribute(""));

src/implementation/ensures.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use crate::implementation::{ContractMode, ContractType, FuncWithContracts};
65
use proc_macro2::TokenStream;
76

8-
pub(crate) fn ensures(
9-
mode: ContractMode,
10-
attr: TokenStream,
11-
toks: TokenStream,
12-
) -> TokenStream {
7+
use crate::implementation::{ContractMode, ContractType, FuncWithContracts};
8+
9+
pub(crate) fn ensures(mode: ContractMode, attr: TokenStream, toks: TokenStream) -> TokenStream {
1310
let ty = ContractType::Ensures;
1411

1512
let func = syn::parse_quote!(#toks);

src/implementation/invariant.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ use syn::{FnArg, ImplItem, ImplItemMethod, Item, ItemFn, ItemImpl};
88

99
use crate::implementation::{ContractMode, ContractType, FuncWithContracts};
1010

11-
pub(crate) fn invariant(
12-
mode: ContractMode,
13-
attr: TokenStream,
14-
toks: TokenStream,
15-
) -> TokenStream {
11+
pub(crate) fn invariant(mode: ContractMode, attr: TokenStream, toks: TokenStream) -> TokenStream {
1612
let item: Item = syn::parse_quote!(#toks);
1713

1814
let name = mode.name().unwrap().to_string() + "invariant";
@@ -27,11 +23,7 @@ pub(crate) fn invariant(
2723
}
2824
}
2925

30-
fn invariant_fn(
31-
mode: ContractMode,
32-
attr: TokenStream,
33-
func: ItemFn,
34-
) -> TokenStream {
26+
fn invariant_fn(mode: ContractMode, attr: TokenStream, func: ItemFn) -> TokenStream {
3527
let ty = ContractType::Invariant;
3628

3729
let f = FuncWithContracts::new_with_initial_contract(func, ty, mode, attr);
@@ -59,8 +51,7 @@ fn invariant_impl(
5951
}
6052
};
6153

62-
let invariant_ident =
63-
syn::Ident::new(&name, proc_macro2::Span::call_site());
54+
let invariant_ident = syn::Ident::new(&name, proc_macro2::Span::call_site());
6455

6556
fn method_uses_self(method: &ImplItemMethod) -> bool {
6657
let inputs = &method.sig.inputs;

0 commit comments

Comments
 (0)