Skip to content

Commit 0b42f4c

Browse files
authored
[cargo-verus] docs: improve instructions about migrating an existing project (#2632)
1 parent c569645 commit 0b42f4c

2 files changed

Lines changed: 45 additions & 4 deletions

File tree

source/docs/guide/src/cargo_verus.md

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,47 @@ This creates a new directory with a correctly-configured `Cargo.toml`, an initia
3333

3434
## Updating an existing Rust project to support Verus
3535

36-
To enable verification for one or more of the crates in your project,
37-
add the following to each of their `Cargo.toml` files:
36+
To enable verification for one or more of the crates in your project, add `vstd` as a
37+
dependency as follows:
38+
39+
```sh
40+
cargo add vstd
41+
```
42+
43+
Then import the Verus prelude in each root module (e.g. `lib.rs` or `main.rs`):
44+
45+
```rust
46+
use vstd::prelude::*;
47+
```
48+
49+
To opt a crate into verification, include the following in its `Cargo.toml`:
3850

3951
```toml
4052
[package.metadata.verus]
4153
verify = true
54+
```
55+
56+
If the crate is not in a workspace, also add the following to suppress warnings
57+
about `cfg(verus_only)`:
4258

59+
```toml
4360
[lints.rust]
4461
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(verus_only)'] }
4562
```
63+
4664
See below for more details.
4765

4866
Note that you can still use normal `cargo` commands (e.g., `cargo build`) on
4967
crates and projects that include Verus annotations.
5068

69+
## The Verus prelude
70+
71+
Each verified crate needs to import the Verus prelude as follows:
72+
73+
```rust
74+
use vstd::prelude::*;
75+
```
76+
5177
## Cargo.toml configuration
5278

5379
Crates that should be verified must opt in by adding a `[package.metadata.verus]`
@@ -72,6 +98,21 @@ unexpected_cfgs = { level = "warn", check-cfg = ['cfg(verus_only)'] }
7298
`cargo verus new` adds this automatically. See [Ghost Erasure](./erasure.md) for a full
7399
explanation of `verus_only` and when to use it.
74100

101+
In a Cargo workspace, you should instead include the following in the root `Cargo.toml`:
102+
103+
```toml
104+
[workspace.lints.rust]
105+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(verus_only)'] }
106+
```
107+
108+
Then ensure that each member crate's `Cargo.toml` has the following (which e.g. `cargo new` adds
109+
automatically):
110+
111+
```toml
112+
[lints.rust]
113+
workspace = true
114+
```
115+
75116
## Subcommands
76117

77118
### `cargo verus verify`
@@ -124,7 +165,7 @@ Note that Verus-annotated code can also be built with a normal `cargo build` com
124165

125166
Arguments are split around `--`:
126167

127-
- **Before `--`**: forwarded to `cargo`
168+
- **Before `--`**: forwarded to `cargo`
128169
- **After `--`**: forwarded to every `verus` invocation
129170

130171
```bash

source/rust_verify/src/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ where
364364

365365
pub(crate) fn no_builtin_err(span: &vir::messages::Span) -> VirErr {
366366
vir::messages::error(span,
367-
"Error: The verus_builtin crate was not imported. This is usually imported via `vstd`, and it is necessary to run Verus.")
367+
"Error: The verus_builtin crate was not imported but it is necessary to run Verus. You likely need to add `use vstd::prelude::*;` at the top of a lib.rs or main.rs file.")
368368
.help("For getting started with Verus, see: https://verus-lang.github.io/verus/guide/getting_started.html")
369369
}
370370

0 commit comments

Comments
 (0)