blob: d05140632185e7a5fe4ad5b71a94547f69a980f0 [file] [log] [blame] [view]
Lukasz Anforowicz8f3d14b2025-10-23 00:09:401# Tips and tricks for a nice Rust development experience
2
3## Using VSCode
4
51. Ensure you're using the `rust-analyzer` extension for VSCode, rather than
6 earlier forms of Rust support.
71. Run `gn` with the `--export-rust-project` flag, such as:
8 `gn gen out/Release --export-rust-project`.
91. `ln -s out/Release/rust-project.json rust-project.json`
101. When you run VSCode, or any other IDE that uses
11 [rust-analyzer](https://rust-analyzer.github.io/) it should detect the
12 `rust-project.json` and use this to give you rich browsing, autocompletion,
13 type annotations etc. for all the Rust within the Chromium codebase.
141. Point rust-analyzer to the rust toolchain in Chromium. Otherwise you will
15 need to install Rustc in your system, and Chromium uses the nightly
16 compiler, so you would need that to match. Add the following to
17 `.vscode/settings.json` in the Chromium checkout (e.g.
18 `chromium/src/.vscode/settings.json`; create the subdirectory and file if
19 they do not already exist):
20 ```
21 {
22 // The rest of the settings...
23
24 "rust-analyzer.cargo.extraEnv": {
25 "PATH": "../../third_party/rust-toolchain/bin:$PATH",
26 }
27 }
28 ```
29 This assumes you are working with an output directory like `out/Debug` which
30 has two levels; adjust the number of `..` in the path according to your own
31 setup.
32
33## Suppressing unused code warnings
34
35We don't want to commit Rust code with unused variables,
36but work-in-progress changes often temporarily have unused code.
37The following options exist for dealing with unused code warnings:
38
39* Avoid warnings by prefixing
40 unused variables, parameters, and other APIs
41 with an underscore character
42 (e.g. using `_foo` rather than `foo` as the name).
43* Temporarily insert `#[!allow(unused)] /* DO NOT
44 SUBMIT */` at the top of the affected `.rs` files.
45 - See `rustc -W help` for a list of warnings covered by the `unused` group
46 of warnings.
47 - You can also use `#![warn(...)]` to still see the warnings, but avoid
48 treating them as errors.
49* Locally set `treat_warnings_as_errors = false` in your `args.gn`.
50 This will affect all Rust and C/C++ warnings.