Since the commit 50384460c68f
("Rewrite method resolution to follow rustc more closely"), the method
resolution logic has changed: rust-analyzer only looks up inherent
methods for primitive types in sysroot crates.
Unfortunately, this change broke at least one project that relies on
`rust-project.json`: Rust-for-Linux. Its auto-generated
`rust-project.json` directly embeds `core`, `alloc`, and `std` in the
`crates` list without defining `sysroot_src`. Consequently,
rust-analyzer fails to identify them as sysroot crates, breaking IDE
support for primitive methods (e.g., `0_i32.rotate_left(0)`).
However, specifying `sysroot_src` creates a new issue: it implicitly
adds `std` as a dependency to all kernel module crates, which are
actually compiled with `-Zcrate-attr=no_std`. Since rust-analyzer cannot
see compiler flags passed outside of the project definition, we need a
method to explicitly specify `#![no_std]` or, more generally,
crate-level attributes through the project configuration.
To resolve this, extend the `rust-project.json` format with a new
`crate_attrs` field. This allows users to specify crate-level attributes
such as `#![no_std]` directly into the configuration, enabling
rust-analyzer to respect them when analyzing crates.
References:
- The original Zulip discussion:
https://rust-lang.zulipchat.com/#narrow/channel/185405-t-compiler.2Frust-analyzer/topic/Primitive.20type.20inherent.20method.20lookup.20fails/with/562983853
rust-analyzer documentation
The rust analyzer manual uses mdbook.
Quick start
To run the documentation site locally:
cargo install mdbook
cargo xtask codegen
cd docs/book
mdbook serve
# make changes to documentation files in doc/book/src
# ...
mdbook will rebuild the documentation as changes are made.
Making updates
While not required, installing the mdbook binary can be helpful in order to see the changes. Start with the mdbook User Guide to familiarize yourself with the tool.
Generated documentation
Four sections are generated dynamically: assists, configuration, diagnostics and features. Their content is found in the generated.md files
of the respective book section, for example src/configuration_generated.md, and are included in the book via mdbook's
include functionality. Generated files can be rebuilt by running the various
test cases that generate them, or by simply running all of the rust-analyzer tests with cargo test and cargo xtask codegen.