Skip to content

Commit 885546c

Browse files
authored
Upgrade mdbook and set global flag to disable play feature (rust-lang#1211)
* Upgrade `mdbook` version * Set global option to disable playground feature * Remove `noplaypen` annotation from Rust code snippets
1 parent c941888 commit 885546c

9 files changed

+39
-35
lines changed

docs/book.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ multilingual = false
1212
site-url = "/kani/"
1313
git-repository-url = "https://github.com/model-checking/kani"
1414
edit-url-template = "https://github.com/model-checking/kani/edit/main/docs/{path}"
15+
16+
[output.html.playground]
17+
runnable = false

docs/build-docs.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
88
cd $SCRIPT_DIR
99

1010
# Download mdbook release (vs spending time building it via cargo install)
11-
FILE="mdbook-v0.4.12-x86_64-unknown-linux-gnu.tar.gz"
12-
URL="https://github.com/rust-lang/mdBook/releases/download/v0.4.12/$FILE"
13-
EXPECTED_HASH="2a0953c50d8156e84f193f15a506ef0adbac66f1942b794de5210ca9ca73dd33"
11+
MDBOOK_VERSION=v0.4.18
12+
FILE="mdbook-${MDBOOK_VERSION}-x86_64-unknown-linux-gnu.tar.gz"
13+
URL="https://github.com/rust-lang/mdBook/releases/download/${MDBOOK_VERSION}/$FILE"
14+
EXPECTED_HASH="d276b0e594d5980de6a7917ce74c348f28d3cb8b353ca4eaae344ae8a4c40bea"
1415
if [ ! -x mdbook ]; then
1516
curl -sSL -o "$FILE" "$URL"
1617
echo "$EXPECTED_HASH $FILE" | sha256sum -c -

docs/src/install-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export PATH=$(pwd)/scripts:$PATH
108108

109109
Create a test file:
110110

111-
```rust,noplaypen
111+
```rust
112112
// File: test.rs
113113
#[kani::proof]
114114
fn main() {

docs/src/regression-testing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ error: test failed: expected check success, got failure
8080
When working on a test that's expected to fail, there are two options to
8181
indicate an expected failure. The first one is to add a comment
8282

83-
```rust,noplaypen
83+
```rust
8484
// kani-<stage>-fail
8585
```
8686
at the top of the test file, where `<stage>` is the stage where the test is
@@ -100,13 +100,13 @@ predicate.
100100
Many tests will require passing command-line options to Kani. These options can
101101
be specified in single Rust files by adding a comment at the top of the file:
102102

103-
```rust,noplaypen
103+
```rust
104104
// kani-flags: <options>
105105
```
106106

107107
For example, to use an unwinding value of 4 in a test, we can write:
108108

109-
```rust,noplaypen
109+
```rust
110110
// kani-flags: --default-unwind 4
111111
```
112112

docs/src/tutorial-first-steps.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ With Kani, all the corner cases are covered from the start, and the new concern
66

77
Consider this first program (which can be found under [`first-steps-v1`](https://github.com/model-checking/kani/tree/main/docs/src/tutorial/first-steps-v1/)):
88

9-
```rust,noplaypen
9+
```rust
1010
{{#include tutorial/first-steps-v1/src/main.rs:code}}
1111
```
1212

@@ -17,7 +17,7 @@ And if this function was more complicated—for example, if some of the branches
1717

1818
We can try to property test a function like this, but if we're naive about it (and consider all possible `u32` inputs), then it's unlikely we'll ever find the bug.
1919

20-
```rust,noplaypen
20+
```rust
2121
{{#include tutorial/first-steps-v1/src/main.rs:proptest}}
2222
```
2323

@@ -31,7 +31,7 @@ There's only 1 in 4 billion inputs that fail, so it's vanishingly unlikely the p
3131

3232
With Kani, however, we can use `kani::any()` to represent all possible `u32` values:
3333

34-
```rust,noplaypen
34+
```rust
3535
{{#include tutorial/first-steps-v1/src/main.rs:kani}}
3636
```
3737

@@ -83,7 +83,7 @@ Try a few other types of errors.
8383

8484
For example, instead of panicking we could try explicitly dereferencing a null pointer:
8585

86-
```rust,noplaypen
86+
```rust
8787
unsafe { return *(0 as *const u32) };
8888
```
8989

@@ -146,7 +146,7 @@ It seems a bit odd that we can take billions of inputs when our function only ha
146146
Let's encode this fact about our function by asserting some reasonable bound on our input, after we've fixed our bug (code available under
147147
[`first-steps-v2`](https://github.com/model-checking/kani/tree/main/docs/src/tutorial/first-steps-v2/)):
148148

149-
```rust,noplaypen
149+
```rust
150150
{{#include tutorial/first-steps-v2/src/main.rs:code}}
151151
```
152152

@@ -172,7 +172,7 @@ This is the purpose of _proof harnesses_.
172172
Much like property testing (which would also fail in this assertion), we need to set up our preconditions, call the function in question, then assert our postconditions.
173173
Here's a revised example of the proof harness, one that now succeeds:
174174

175-
```rust,noplaypen
175+
```rust
176176
{{#include tutorial/first-steps-v2/src/main.rs:kani}}
177177
```
178178

docs/src/tutorial-kinds-of-failure.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@ In this section, we're going to expand on these additional checks, to give you a
1010
Rust is safe by default, and so includes dynamic (run-time) bounds checking where needed.
1111
Consider this Rust code (available [here](https://github.com/model-checking/kani/blob/main/docs/src/tutorial/kinds-of-failure/src/bounds_check.rs)):
1212

13-
```rust,noplaypen
13+
```rust
1414
{{#include tutorial/kinds-of-failure/src/bounds_check.rs:code}}
1515
```
1616

1717
We can again write a simple property test against this code:
1818

19-
```rust,noplaypen
19+
```rust
2020
{{#include tutorial/kinds-of-failure/src/bounds_check.rs:proptest}}
2121
```
2222

2323
This property test will immediately find the failing case because of this dynamic check.
2424

2525
But what if we change this function to use unsafe Rust?
2626

27-
```rust,noplaypen
27+
```rust
2828
return unsafe { *a.get_unchecked(i % a.len() + 1) };
2929
```
3030

@@ -38,7 +38,7 @@ test bounds_check::tests::doesnt_crash ... ok
3838

3939
But we're able to write a harness for this unsafe code:
4040

41-
```rust,noplaypen
41+
```rust
4242
{{#include tutorial/kinds-of-failure/src/bounds_check.rs:kani}}
4343
```
4444

@@ -136,7 +136,7 @@ These two techniques should help you find both the nondeterministic inputs, and
136136

137137
Consider a different variant on the function above:
138138

139-
```rust,noplaypen
139+
```rust
140140
fn get_wrapped(i: usize, a: &[u32]) -> u32 {
141141
return a[i % a.len()];
142142
}
@@ -150,7 +150,7 @@ Kani will spot this not as a bound error, but as a mathematical error: on an emp
150150
Rust also performs runtime safety checks for integer overflows, much like it does for bounds checks.
151151
Consider this code (available [here](https://github.com/model-checking/kani/blob/main/docs/src/tutorial/kinds-of-failure/src/overflow.rs)):
152152

153-
```rust,noplaypen
153+
```rust
154154
{{#include tutorial/kinds-of-failure/src/overflow.rs:code}}
155155
```
156156

@@ -177,7 +177,7 @@ For instance, instead of `a + b` write `a.wrapping_add(b)`.
177177
One of the classic subtle bugs that persisted in many implementations for a very long time is finding the midpoint in quick sort.
178178
This often naively looks like this (code available [here](https://github.com/model-checking/kani/blob/main/docs/src/tutorial/kinds-of-failure/src/overflow_quicksort.rs)):
179179

180-
```rust,noplaypen
180+
```rust
181181
{{#include tutorial/kinds-of-failure/src/overflow_quicksort.rs:code}}
182182
```
183183

@@ -193,7 +193,7 @@ Don't add that right away, see what happens if you don't. Just keep it in mind.)
193193

194194
A very common approach for resolving the overflow issue looks like this:
195195

196-
```rust,noplaypen
196+
```rust
197197
return low + (high - low) / 2;
198198
```
199199

@@ -206,7 +206,7 @@ After all, what does "correct" even mean?
206206
Often we're using a good approximation of correct, such as the equivalence of two implementations (often one much "simpler" than the other somehow).
207207
Here's one possible assertion to make that obvious:
208208

209-
```rust,noplaypen
209+
```rust
210210
assert!(result as u64 == (a as u64 + b as u64) / 2);
211211
```
212212

docs/src/tutorial-loop-unwinding.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
Consider code like this (available [here](https://github.com/model-checking/kani/blob/main/docs/src/tutorial/loops-unwinding/src/lib.rs)):
44

5-
```rust,noplaypen
5+
```rust
66
{{#include tutorial/loops-unwinding/src/lib.rs:code}}
77
```
88

99
This code has an off-by-one error that only occurs on the last iteration of the loop (when called with an input that will trigger it).
1010
We can try to find this bug with a proof harness like this:
1111

12-
```rust,noplaypen
12+
```rust
1313
{{#include tutorial/loops-unwinding/src/lib.rs:kani}}
1414
```
1515

@@ -84,7 +84,7 @@ Kani is now sure we've unwound the loop enough to verify our proof harness, and
8484
Kani allows three options to specify the unwind value for a particular harness:
8585

8686
1. The unwind annotation `#[kani::unwind(<num>)]`. This sets the unwind value for the harness with the annotation. Example -
87-
``` rust,noplaypen
87+
``` rust
8888
#[kani::proof]
8989
#[kani::unwind(3)]
9090
fn proof_harness() {

docs/src/tutorial-nondeterministic-variables.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ In this tutorial, we will show how to:
1616
Let's say you're developing an inventory management tool, and you would like to verify that your API to manage items is correct.
1717
Here is a simple implementation of this API:
1818

19-
```rust,noplaypen
19+
```rust
2020
{{#include tutorial/arbitrary-variables/src/inventory.rs:inventory_lib}}
2121
```
2222

2323
Now we would like to verify that, no matter which combination of `id` and `quantity`, a call to `Inventory::update()` followed by a call to `Inventory::get()` using the same `id` returns some value that's equal to the one we inserted:
2424

25-
```rust,noplaypen
25+
```rust
2626
{{#include tutorial/arbitrary-variables/src/inventory.rs:safe_update}}
2727
```
2828

@@ -47,7 +47,7 @@ That said, there may be cases where you want to verify your code taking into con
4747

4848
Let's see what happens if we modify our verification harness to use the unsafe method `kani::any_raw()` to generate the updated value.
4949

50-
```rust,noplaypen
50+
```rust
5151
{{#include tutorial/arbitrary-variables/src/inventory.rs:unsafe_update}}
5252
```
5353

@@ -68,7 +68,7 @@ cargo kani --harness unsafe_update
6868
Now you would like to add a new structure to your library that allow users to represent a review rating, which can go from 0 to 5 stars.
6969
Let's say you add the following implementation:
7070

71-
```rust,noplaypen
71+
```rust
7272
{{#include tutorial/arbitrary-variables/src/rating.rs:rating_struct}}
7373
```
7474

@@ -77,13 +77,13 @@ The easiest way to allow users to create nondeterministic variables of the Ratin
7777
The implementation only requires you to define a check to your structure that returns whether its current value is valid or not.
7878
In our case, we have the following implementation:
7979

80-
```rust,noplaypen
80+
```rust
8181
{{#include tutorial/arbitrary-variables/src/rating.rs:rating_invariant}}
8282
```
8383

8484
Now you can use `kani::any()` to create valid nondeterministic variables of the Rating type as shown in this harness:
8585

86-
```rust,noplaypen
86+
```rust
8787
{{#include tutorial/arbitrary-variables/src/rating.rs:verify_rating}}
8888
```
8989

docs/src/verification-results.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ because the property is unreachable, or because the harness is
2727
_over-constrained_.
2828

2929
Example:
30-
```rust,noplaypen
30+
```rust
3131
{{#include getting-started/verification-results/src/main.rs:success_example}}
3232
```
3333
The output from Kani indicates that the assertion holds:
@@ -43,7 +43,7 @@ hold). In this case, you can examine a trace by re-running with the
4343
information.
4444

4545
Example:
46-
```rust,noplaypen
46+
```rust
4747
{{#include getting-started/verification-results/src/main.rs:failure_example}}
4848
```
4949
The assertion doesn't hold as Kani's output indicates:
@@ -67,7 +67,7 @@ Kani currently checks reachability for the following assertion types:
6767

6868
Example:
6969

70-
```rust,noplaypen
70+
```rust
7171
{{#include getting-started/verification-results/src/main.rs:unreachable_example}}
7272
```
7373

@@ -85,7 +85,7 @@ that is not currently supported by Kani. See
8585
Rust language features.
8686

8787
Example:
88-
```rust,noplaypen
88+
```rust
8989
{{#include getting-started/verification-results/src/main.rs:undetermined_example}}
9090
```
9191
The output from Kani indicates that the assertion is undetermined due to the

0 commit comments

Comments
 (0)