-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unresolved extern crate
for test crate
#6714
Comments
https://github.com/rust-analyzer/rust-analyzer/blob/10e3a9879c8714320f9a0729d647da7877f0a753/crates/project_model/src/sysroot.rs#L40 only lists core, alloc and std. Maybe test isn't included as it is an unstable crate? |
same. can we please get a response on this? |
These crates are unconditionally added as dependencies to each crate, IIRC. We probably don't want to do that for |
I wonder how/if rust-analyzer handles the What would happen if the |
We don't handle the no_std case. In principle, we should be handling it the same way, yes. Adding |
I think we meet the same issue in priroda (cc @bjorn3), where (Could building a custom crate graph JSON work? It would be nice to have some way to manually specify 'miri' depends on the rustc private crates) |
This works around <rust-lang/rust-analyzer#6714>
For |
Yes, I do have that set up, and I think it's set up properly. That works for the root crate ( |
7891: Improve handling of rustc_private r=matklad a=DJMcNab This PR changes how `rust-analyzer` handles `rustc_private`. In particular, packages now must opt-in to using `rustc_private` in `Cargo.toml`, by adding: ```toml [package.metadata.rust-analyzer] rustc_private=true ``` This means that depending on crates which also use `rustc_private` will be significantly improved, since their dependencies on the `rustc_private` crates will be resolved properly. A similar approach could be used in #6714 to allow annotating that your package uses the `test` crate, although I have not yet handled that in this PR. Additionally, we now only index the crates which are transitive dependencies of `rustc_driver` in the `rustcSource` directory. This should not cause any change in behaviour when using `rustcSource: "discover"`, as the source used then will only be a partial clone. However, if `rustcSource` pointing at a local checkout of rustc, this should significantly improve the memory usage and lower indexing time. This is because we avoids indexing all crates in `src/tools/`, which includes `rust-analyzer` itself. Furthermore, we also prefer named dependencies over dependencies from `rustcSource`. This ensures that feature resolution for crates which are depended on by both `rustc` and your crate uses the correct set for analysing your crate. See also [introductory zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Fixed.20crate.20graphs.20and.20optional.20builtin.20crates/near/229086673) I have tested this in [priroda](https://github.com/oli-obk/priroda/), and it provides a significant improvement to the development experience (once I give `miri` the required data in `Cargo.toml`) Todo: - [ ] Documentation This is ready to review, and I will add documentation if this would be accepted (or if I get time to do so anyway) Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
7891: Improve handling of rustc_private r=matklad a=DJMcNab This PR changes how `rust-analyzer` handles `rustc_private`. In particular, packages now must opt-in to using `rustc_private` in `Cargo.toml`, by adding: ```toml [package.metadata.rust-analyzer] rustc_private=true ``` This means that depending on crates which also use `rustc_private` will be significantly improved, since their dependencies on the `rustc_private` crates will be resolved properly. A similar approach could be used in #6714 to allow annotating that your package uses the `test` crate, although I have not yet handled that in this PR. Additionally, we now only index the crates which are transitive dependencies of `rustc_driver` in the `rustcSource` directory. This should not cause any change in behaviour when using `rustcSource: "discover"`, as the source used then will only be a partial clone. However, if `rustcSource` pointing at a local checkout of rustc, this should significantly improve the memory usage and lower indexing time. This is because we avoids indexing all crates in `src/tools/`, which includes `rust-analyzer` itself. Furthermore, we also prefer named dependencies over dependencies from `rustcSource`. This ensures that feature resolution for crates which are depended on by both `rustc` and your crate uses the correct set for analysing your crate. See also [introductory zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Fixed.20crate.20graphs.20and.20optional.20builtin.20crates/near/229086673) I have tested this in [priroda](https://github.com/oli-obk/priroda/), and it provides a significant improvement to the development experience (once I give `miri` the required data in `Cargo.toml`) Todo: - [ ] Documentation This is ready to review, and I will add documentation if this would be accepted (or if I get time to do so anyway) Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
This works around <rust-lang/rust-analyzer#6714>
I think we need to add a config like
|
@flodiebold This is just my curiosity here but what constraints exactly require a "fixed crate graph"? I know about rust-analyzer's graph-query model in the broad sense, I'm not sure why that requires fixedness here. |
What I meant by that is that we need to know the crate graph before analyzing the code, it can't change in response to things we find during name resolution. The reason for that is that the crate graph is an input for rust-analyzer. Of course nothing is impossible, this is just a simplifying assumption, but it's pretty pervasive, I think. I imagine it might be possible to solve this by instead having a "preliminary" crate graph as input, where possible sysroot dependencies are specifically marked, and then having name resolution (the |
Polite little bump 🙇♂️ Ran into this when using
if i'm not mistaken, this disables all unresolved extern crate warnings, which is probably not an ideal user experience either. |
I'm using benchmarking on nightly through the
test
feature, which requiresextern crate test
in the code. However, rust-anaylzer always marks this asunresolved extern crate
and I have seen no other reports of this,so I'm asking here whether that is a bug from rust-analyzer that it doesn't know about this default crate or whether I did a misconfiguration by using nightly.
I am running Arch Linux and the LSP plugin for Sublime Text.
The text was updated successfully, but these errors were encountered: