Skip to content

Commit 50748b9

Browse files
committed
chore: standardize formatting
1 parent 220d8e4 commit 50748b9

File tree

7 files changed

+83
-120
lines changed

7 files changed

+83
-120
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
/target
2-
31
# rust
42
/target/
53
**/*.rs.bk
64

75
# direnv
6+
/.toolchain/
87
/.direnv/
98

109
# code coverage

.taplo.toml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ column_width = 110
77
[[rule]]
88
include = ["**/Cargo.toml"]
99
keys = [
10-
"dependencies",
11-
"*-dependencies",
12-
"workspace.dependencies",
13-
"workspace.*-dependencies",
14-
"target.*.dependencies",
15-
"target.*.*-dependencies",
10+
"dependencies",
11+
"*-dependencies",
12+
"workspace.dependencies",
13+
"workspace.*-dependencies",
14+
"target.*.dependencies",
15+
"target.*.*-dependencies",
1616
]
1717
formatting.reorder_keys = true
1818

1919
[[rule]]
2020
include = ["**/Cargo.toml"]
2121
keys = [
22-
"dependencies.*",
23-
"*-dependencies.*",
24-
"workspace.dependencies.*",
25-
"workspace.*-dependencies.*",
26-
"target.*.dependencies",
27-
"target.*.*-dependencies",
22+
"dependencies.*",
23+
"*-dependencies.*",
24+
"workspace.dependencies.*",
25+
"workspace.*-dependencies.*",
26+
"target.*.dependencies",
27+
"target.*.*-dependencies",
2828
]
2929
formatting.reorder_keys = false

CHANGELOG.md

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Changelog
1+
# Changelog
2+
23
All notable changes to this project will be documented in this file.
34

4-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## Unreleased
88

@@ -17,8 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717

1818
### Changed
1919

20-
- better handling of mutable borrows and lifetime relationships for functions
21-
with contracts
20+
- better handling of mutable borrows and lifetime relationships for functions with contracts
2221

2322
## [0.6.1] - 2021-07-13
2423

@@ -27,65 +26,77 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2726
- support for `impl Trait` return types
2827

2928
## [0.6.0] - 2020-09-05
29+
3030
### Changed
31+
3132
- `pre` is now `requires`
3233
- `post` is now `ensures`
3334

3435
## [0.5.2] - 2020-09-05
36+
3537
### Fixed
38+
3639
- Unused braces in function body generated code are removed
3740

3841
## [0.5.1] - 2020-08-06
42+
3943
### Changed
44+
4045
- Trait methods now handle attributes better.
4146

4247
## [0.5.0] - 2020-08-06
48+
4349
### Changed
50+
4451
- Implication operator is now `->`.
4552

4653
## [0.4.0] - 2020-05-01
54+
4755
### Added
56+
4857
- Added support for MIRAI assertions
4958
- Added implication operator
5059

5160
## [0.3.0] - 2019-07-20
61+
5262
### Added
63+
5364
- Pseudo-function `old(expr)` which in a post-condition evaluates the expression before function execution.
5465
- Automatic generation of documentation containing all contracts.
5566

5667
## [0.2.2] - 2019-07-17
68+
5769
### Fixed
70+
5871
- Errors inside functions/methods are now properly reported with the correct source location.
72+
5973
### Changed
74+
6075
- internal handling of contracts is now done in a single proc-macro pass instead of one for each contract.
6176

6277
## [0.2.1] - 2019-06-07
78+
6379
### Fixed
80+
6481
- Functions/methods with explicit return statements no longer skip `post` conditions
6582

6683
## [0.2.0] - 2014-04-12
84+
6785
### Added
86+
6887
- `contract_trait` attribute to make all implementors of a trait respect contracts.
6988

7089
## [0.1.1] - 2019-04-08
90+
7191
### Added
92+
7293
- Feature flags to override contract behavior.
7394
- `disable_contracts` ignores all checks
7495
- `override_debug` only checks contracts in debug configurations.
7596
- `override_log` only prints using the `log`-crate interface.
7697

7798
## [0.1.0] - 2019-04-06
78-
### Added
79-
- attributes `pre`/`post`/`invariant` and `debug_` versions of each.
80-
81-
82-
83-
84-
85-
86-
87-
88-
89-
9099

100+
### Added
91101

102+
- attributes `pre`/`post`/`invariant` and `debug_` versions of each.

Cargo.toml

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
11
[package]
22
name = "contracts"
33
version = "0.6.3"
4+
description = "Design-by-contract attributes"
45
authors = ["karroffel <[email protected]>"]
56
edition = "2018"
67
repository = "https://gitlab.com/karroffel/contracts"
78
license = "MPL-2.0"
8-
readme = "README.md"
9-
categories = [
10-
"development-tools",
11-
"development-tools::procedural-macro-helpers",
12-
]
13-
keywords = [
14-
"design-by-contract",
15-
"precondition",
16-
"postcondition",
17-
"invariant",
18-
"verification",
19-
]
20-
documentation = "https://docs.rs/contracts"
21-
description = "Design-by-contract attributes"
22-
23-
[badges]
24-
gitlab = { repository = "karroffel/contracts", branch = "master" }
9+
categories = ["development-tools", "development-tools::procedural-macro-helpers"]
10+
keywords = ["design-by-contract", "precondition", "postcondition", "invariant", "verification"]
2511

2612
[lib]
2713
name = "contracts"
@@ -35,7 +21,6 @@ override_log = []
3521
mirai_assertions = []
3622

3723
[dependencies]
38-
syn = { version = "1.0", features = ["extra-traits", "full", "visit", "visit-mut"] }
39-
quote = "1.0"
4024
proc-macro2 = "1.0"
41-
25+
quote = "1.0"
26+
syn = { version = "1.0", features = ["extra-traits", "full", "visit", "visit-mut"] }

README.md

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
# *Design By Contract* for Rust
1+
# _Design By Contract_ for Rust
22

3-
[![License][license]][LICENSE]
4-
![Build status][build]
5-
![Lines of Code][loc]
3+
[![License][license]][LICENSE] ![Build status][build] ![Lines of Code][loc]
64

75
[license]: https://img.shields.io/badge/license-MPL%202.0-blue.svg
86
[build]: https://gitlab.com/karroffel/contracts/badges/master/pipeline.svg
97
[loc]: https://tokei.rs/b1/gitlab/karroffel/contracts?category=code
108

11-
Annotate functions and methods with "contracts", using *invariants*,
12-
*pre-conditions* and *post-conditions*.
9+
Annotate functions and methods with "contracts", using _invariants_, _pre-conditions_ and _post-conditions_.
1310

14-
[Design by contract][dbc] is a popular method to augment code with formal
15-
interface specifications.
16-
These specifications are used to increase the correctness of the code by
17-
checking them as assertions at runtime.
11+
[Design by contract][dbc] is a popular method to augment code with formal interface specifications. These specifications are used to increase the correctness of the code by checking them as assertions at runtime.
1812

1913
[dbc]: https://en.wikipedia.org/wiki/Design_by_contract
2014

@@ -71,10 +65,9 @@ This crate exposes the `requires`, `ensures` and `invariant` attributes.
7165

7266
- `requires` are checked before a function/method is executed.
7367
- `ensures` are checked after a function/method ran to completion
74-
- `invariant`s are checked both before *and* after a function/method ran.
68+
- `invariant`s are checked both before _and_ after a function/method ran.
7569

76-
Additionally, all those attributes have versions with different "modes". See
77-
[the Modes section](#Modes) below.
70+
Additionally, all those attributes have versions with different "modes". See [the Modes section](#Modes) below.
7871

7972
For `trait`s and trait `impl`s the `contract_trait` attribute can be used.
8073

@@ -84,9 +77,7 @@ More specific information can be found in the crate documentation.
8477

8578
### `old()` function
8679

87-
One unique feature that this crate provides is an `old()` pseudo-function which
88-
allows to perform checks using a value of a parameter before the function call
89-
happened. This is only available in `ensures` attributes.
80+
One unique feature that this crate provides is an `old()` pseudo-function which allows to perform checks using a value of a parameter before the function call happened. This is only available in `ensures` attributes.
9081

9182
```rust
9283
#[ensures(*x == old(*x) + 1, "after the call `x` was incremented")]
@@ -97,9 +88,7 @@ fn incr(x: &mut usize) {
9788

9889
### `->` operator
9990

100-
For more complex functions it can be useful to express behaviour using logical
101-
implication. Because Rust does not feature an operator for implication, this
102-
crate adds this operator for use in attributes.
91+
For more complex functions it can be useful to express behaviour using logical implication. Because Rust does not feature an operator for implication, this crate adds this operator for use in attributes.
10392

10493
```rust
10594
#[ensures(person_name.is_some() -> ret.contains(person_name.unwrap()))]
@@ -116,26 +105,17 @@ fn geeting(person_name: Option<&str>) -> String {
116105

117106
This operator is right-associative.
118107

119-
**Note**: Because of the design of `syn`, it is tricky to add custom operators
120-
to be parsed, so this crate performs a rewrite of the `TokenStream` instead.
121-
The rewrite works by separating the expression into a part that's left of the
122-
`->` operator and the rest on the right side. This means that
123-
`if a -> b { c } else { d }` will not generate the expected code.
124-
Explicit grouping using parenthesis or curly-brackets can be used to avoid this.
125-
108+
**Note**: Because of the design of `syn`, it is tricky to add custom operators to be parsed, so this crate performs a rewrite of the `TokenStream` instead. The rewrite works by separating the expression into a part that's left of the `->` operator and the rest on the right side. This means that `if a -> b { c } else { d }` will not generate the expected code. Explicit grouping using parenthesis or curly-brackets can be used to avoid this.
126109

127110
## Modes
128111

129112
All the attributes (requires, ensures, invariant) have `debug_*` and `test_*` versions.
130113

131-
- `debug_requires`/`debug_ensures`/`debug_invariant` use `debug_assert!`
132-
internally rather than `assert!`
133-
- `test_requires`/`test_ensures`/`test_invariant` guard the `assert!` with an
134-
`if cfg!(test)`.
135-
This should mostly be used for stating equivalence to "slow but obviously
136-
correct" alternative implementations or checks.
137-
114+
- `debug_requires`/`debug_ensures`/`debug_invariant` use `debug_assert!` internally rather than `assert!`
115+
- `test_requires`/`test_ensures`/`test_invariant` guard the `assert!` with an `if cfg!(test)`. This should mostly be used for stating equivalence to "slow but obviously correct" alternative implementations or checks.
116+
138117
For example, a merge-sort implementation might look like this
118+
139119
```rust
140120
#[test_ensures(is_sorted(input))]
141121
fn merge_sort<T: Ord + Copy>(input: &mut [T]) {
@@ -145,19 +125,16 @@ All the attributes (requires, ensures, invariant) have `debug_*` and `test_*` ve
145125

146126
## Set-up
147127

148-
To install the latest version, add `contracts` to the dependency section of the
149-
`Cargo.toml` file.
128+
To install the latest version, add `contracts` to the dependency section of the `Cargo.toml` file.
150129

151130
```
152131
[dependencies]
153132
contracts = "0.6.3"
154133
```
155134

156-
To then bring all procedural macros into scope, you can add `use contracts::*;`
157-
in all files you plan to use the contract attributes.
135+
To then bring all procedural macros into scope, you can add `use contracts::*;` in all files you plan to use the contract attributes.
158136

159-
Alternatively use the "old-style" of importing macros to have them available
160-
project-wide.
137+
Alternatively use the "old-style" of importing macros to have them available project-wide.
161138

162139
```rust
163140
#[macro_use]
@@ -168,20 +145,14 @@ extern crate contracts;
168145

169146
This crate exposes a number of feature flags to configure the assertion behavior.
170147

171-
- `disable_contracts` - disables all checks and assertions.
172-
- `override_debug` - changes all contracts (except `test_` ones) into `debug_*`
173-
versions
174-
- `override_log` - changes all contracts (except `test_` ones) into a
175-
`log::error!()` call if the condition is violated.
176-
No abortion happens.
177-
- `mirai_assertions` - instead of regular assert! style macros, emit macros
178-
used by the [MIRAI] static analyzer. For more documentation of this usage,
179-
head to the [MIRAI] repo.
148+
- `disable_contracts` - disables all checks and assertions.
149+
- `override_debug` - changes all contracts (except `test_` ones) into `debug_*` versions
150+
- `override_log` - changes all contracts (except `test_` ones) into a `log::error!()` call if the condition is violated. No abortion happens.
151+
- `mirai_assertions` - instead of regular assert! style macros, emit macros used by the [MIRAI] static analyzer. For more documentation of this usage, head to the [MIRAI] repo.
180152

181153
[MIRAI]: https://github.com/facebookexperimental/MIRAI
182154

183155
## TODOs
184156

185-
- implement more contracts for traits.
186-
- add a static analyzer à la SPARK for whole-projects using the contracts to
187-
make static assertions.
157+
- implement more contracts for traits.
158+
- add a static analyzer à la SPARK for whole-projects using the contracts to make static assertions.

RELEASE_CHECKLIST.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
2. Run `cargo run --example library` to make sure the examples still run properly
55
3. Run `cargo fmt`
66
4. Change version numbers
7-
- inside `README.md` in the "Set-up" section
8-
- inside `Cargo.toml`
7+
- inside `README.md` in the "Set-up" section
8+
- inside `Cargo.toml`
99
5. Write or finish entry in `CHANGELOG.md`
1010
6. Run `cargo doc --open` and check if the documentation looks fine and is up to date
1111
7. Run `cargo package` and check the output for any unwanted or missing files
12-
8. Run `cargo publish` to upload to crates.io
12+
8. Run `cargo publish` to upload to crates.io

0 commit comments

Comments
 (0)