Skip to content

Commit 92d3365

Browse files
committed
Add a section with recommended setup for Rust Analyzer (model-checking#4504)
Add a section in the docs on the recommended setup to get Rust Analyzer to analyze Kani code. Resolves model-checking#1712 model-checking#3778 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent 5866a51 commit 92d3365

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

docs/src/usage.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,27 @@ This will ensure that a normal build of your code will be completely unaffected
106106
This conditional compilation with `cfg(kani)` (as seen above) is still required for Kani proofs placed under `tests/`.
107107
When this code is built by `cargo test`, the `kani` crate is not available, and so it would otherwise cause build failures.
108108
(Whereas the use of `dev-dependencies` under `tests/` does not need to be gated with `cfg(test)` since that code is already only built when testing.)
109+
110+
## Rust Analyzer Setup
111+
112+
If you are using Rust Analyzer (e.g. in VS Code), we recommend using the following setup to allow Rust Analyzer to analyze Kani-specific code (e.g. Kani annotations, APIs, etc.) and get proper code completion and error:
113+
114+
1. Add the following to your package's `Cargo.toml`:
115+
```toml
116+
[target.'cfg(kani_ra)'.dependencies]
117+
kani = { git = "https://github.com/model-checking/kani" }
118+
```
119+
120+
This adds Kani as a dependency that is conditional on `kani_ra`.
121+
122+
2. Add the following to your Rust Analyzer configuration file (e.g. `settings.json` for VS Code):
123+
```
124+
"rust-analyzer.cargo.extraEnv": {
125+
"RUSTFLAGS": "--cfg kani_ra --cfg kani",
126+
"RUSTUP_TOOLCHAIN": "nightly"
127+
},
128+
```
129+
Explanation:
130+
- Enabling the `kani_ra` configuration allows Rust Analyzer to see the Kani definitions in the crate added in the `Cargo.toml` file.
131+
- Enabling the `kani` configuration enables blocks guarded by `#[cfg(kani)]`.
132+
- Finally, using the nightly toolchain is necessary for Rust Analyzer to be able to handle the code in the Kani dependency, many of which requires nightly features.

0 commit comments

Comments
 (0)