Skip to content

Commit 90f445f

Browse files
authored
Merge pull request #2729 from reddevilmidzy/oot
Add rust-analyzer setup for out-of-tree rustc_private crates
2 parents 09ceddc + a242f32 commit 90f445f

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140

141141
- [Command-line arguments](./cli.md)
142142
- [rustc_driver and rustc_interface](./rustc-driver/intro.md)
143-
- [Remarks on perma-unstable features](./rustc-driver/remarks-on-perma-unstable-features.md)
143+
- [External rustc_drivers](./rustc-driver/external-rustc-drivers.md)
144144
- [Example: Type checking](./rustc-driver/interacting-with-the-ast.md)
145145
- [Example: Getting diagnostics](./rustc-driver/getting-diagnostics.md)
146146
- [Errors and lints](diagnostics.md)

src/rustc-driver/remarks-on-perma-unstable-features.md renamed to src/rustc-driver/external-rustc-drivers.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Remarks on perma unstable features
1+
# External `rustc_driver`s
22

33
## `rustc_private`
44

@@ -49,6 +49,29 @@ For custom-built toolchains or environments not using rustup, additional configu
4949
```
5050
3. **Check version compatibility**: Ensure your LLVM version is compatible with your Rust toolchain
5151

52+
### Configuring `rust-analyzer` for Out-of-Tree Projects
53+
54+
When developing out-of-tree projects that use `rustc_private` crates, you can configure `rust-analyzer` to recognize these crates.
55+
56+
#### Configuration Steps
57+
58+
1. **Set rust-analyzer configuration**
59+
Configure `rust-analyzer.rustc.source` to `"discover"` in your editor settings.
60+
For VS Code, add to `rust_analyzer_settings.json`:
61+
```json
62+
{
63+
"rust-analyzer.rustc.source": "discover"
64+
}
65+
```
66+
2. **Add metadata to Cargo.toml**
67+
Add the following to the `Cargo.toml` of every crate that uses `rustc_private`:
68+
```toml
69+
[package.metadata.rust-analyzer]
70+
rustc_private = true
71+
```
72+
73+
This configuration allows `rust-analyzer` to properly recognize and provide IDE support for `rustc_private` crates in out-of-tree projects.
74+
5275
### Additional Resources
5376

5477
- [GitHub Issue #137421](https://github.com/rust-lang/rust/issues/137421): Explains that `rustc_private` linker failures often occur because `llvm-tools` is not installed

0 commit comments

Comments
 (0)