fix: Build non-ambiguous monikers in crates with multiple targets - #23173
Open
nicolas-guichard wants to merge 5 commits into
Open
fix: Build non-ambiguous monikers in crates with multiple targets#23173nicolas-guichard wants to merge 5 commits into
nicolas-guichard wants to merge 5 commits into
Conversation
nicolas-guichard
force-pushed
the
push-xuslvlqqmyoq
branch
4 times, most recently
from
August 17, 2026 17:10
9e255bf to
f23bf7e
Compare
We need the target kind to be accessible from the ide crate to be able to build non-ambiguous monikers in `StaticIndex`. This only moves the enum definition, actually passing the data down happens in the next commit.
Now that the type is accessible in base_db, this actually stores it in `CrateData` and replaces every use of `CrateData::is_proc_macro` with `CrateData::target_kind::is_proc_macro`. The `TargetKind` used in tests is always `Lib` for now.
I want to add an extra field to this tuple, let's make it a struct for readability.
When writing a test, it's now possible possible to set a custom target kind per crate, by prepending the target kind to the crate name. For instance writing `crate:bin:main` will set `CrateData::target_kind` to `TargetKind::Bin`.
Previously, a crate which defined multiple targets would cause
ambiguous monikers to be built.
For instance when generating an SCIP index in a simple project with a
lib and a bin target:
```
scip-collision/
├── Cargo.toml
└── src/
├── lib.rs
└── main.rs
```
main.rs:
```
struct S;
fn main() {}
```
lib.rs:
```
struct S;
```
`rust-analyzer scip scip-collision` complained with:
```
Duplicate symbols encountered:
src/lib.rs:0:0-1:0
Duplicate symbol: rust-analyzer cargo scip-collision 0.1.0 crate/
src/lib.rs:0:7-0:8
Duplicate symbol: rust-analyzer cargo scip-collision 0.1.0 S#
```
This fixes the ambiguity by adding the target type and name° to each
symbol's moniker. For the example above we now get these symbols:
- `rust-analyzer cargo scip-collision 0.1.0 bin/scip_collision/`
- `rust-analyzer cargo scip-collision 0.1.0 bin/scip_collision/S#`
- `rust-analyzer cargo scip-collision 0.1.0 bin/scip_collision/main().`
- `rust-analyzer cargo scip-collision 0.1.0 lib/`
- `rust-analyzer cargo scip-collision 0.1.0 lib/S#`
°: this doesn't add the name for lib, proc-macro and build script
targets because there's only one of each per Cargo package.
nicolas-guichard
force-pushed
the
push-xuslvlqqmyoq
branch
from
August 17, 2026 19:54
f23bf7e to
b308ed9
Compare
Collaborator
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, a crate which defined multiple targets would cause ambiguous monikers to be built.
For instance when generating an SCIP index in a simple project with a lib and a bin target:
main.rs:
lib.rs:
rust-analyzer scip scip-collisioncomplained with:This fixes the ambiguity by adding the target type and name° to each symbol's moniker. For the example above we now get these symbols:
rust-analyzer cargo scip-collision 0.1.0 bin/scip_collision/rust-analyzer cargo scip-collision 0.1.0 bin/scip_collision/S#rust-analyzer cargo scip-collision 0.1.0 bin/scip_collision/main().rust-analyzer cargo scip-collision 0.1.0 lib/rust-analyzer cargo scip-collision 0.1.0 lib/S#°: this doesn't add the name for lib, proc-macro and build script targets because there's only one of each per Cargo package