Skip to content

Commit 80e311b

Browse files
committed
test: notes on issue 18
1 parent 55c210b commit 80e311b

File tree

5 files changed

+44
-23
lines changed

5 files changed

+44
-23
lines changed

README.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,12 @@ All the attributes (requires, ensures, invariant) have `debug_*` and `test_*` ve
127127

128128
To install the latest version, add `contracts` to the dependency section of the `Cargo.toml` file.
129129

130-
```
131-
[dependencies]
132-
contracts = "0.6.3"
130+
```shell
131+
$ cargo add contracts
133132
```
134133

135134
To then bring all procedural macros into scope, you can add `use contracts::*;` in all files you plan to use the contract attributes.
136135

137-
Alternatively use the "old-style" of importing macros to have them available project-wide.
138-
139-
```rust
140-
#[macro_use]
141-
extern crate contracts;
142-
```
143-
144136
## Configuration
145137

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

RELEASE_CHECKLIST.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

justfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ test-msrv: downgrade-for-msrv
5252
@just toolchain={{ msrv_rustup }} test-no-coverage
5353

5454
# Test workspace and generate Codecov coverage file
55+
5556
test-coverage-codecov:
5657
cargo {{ toolchain }} llvm-cov --workspace --all-features --codecov --output-path codecov.json
5758

rustfmt.toml

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/issues.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#[test]
2+
fn gl_issue_18() {
3+
use std::ops::{Div, Mul, Rem, Sub};
4+
5+
// use contracts::ensures; // <- unused warning
6+
use contracts::requires;
7+
8+
trait Zero {
9+
fn zero() -> Self;
10+
}
11+
12+
impl Zero for u32 {
13+
fn zero() -> Self {
14+
0
15+
}
16+
}
17+
18+
#[requires( n != T::zero() || d != T::zero() )]
19+
#[ensures( ret != T::zero() && n % ret == T::zero() && d % ret == T::zero() )]
20+
fn euclidean<T>(n: T, d: T) -> T
21+
where
22+
T: Sub<Output = T>
23+
+ Mul<Output = T>
24+
+ Div<Output = T>
25+
+ Rem<Output = T>
26+
+ Ord
27+
+ Zero
28+
+ Copy,
29+
{
30+
let (mut a, mut b) = (n.max(d), n.min(d));
31+
while b != T::zero() {
32+
let q: T = a / b;
33+
let r: T = a - q * b;
34+
a = b;
35+
b = r;
36+
}
37+
a
38+
}
39+
40+
assert_eq!(1, euclidean(3, 4));
41+
}

0 commit comments

Comments
 (0)