-
Notifications
You must be signed in to change notification settings - Fork 1.7k
rust-analyzer fails to resolve imports between circular dev-dependent crates #11410
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
Comments
This is likely a duplicate of #9574. |
None of them are remotely necessary, if we import the trick from bevyengine#2851 This works around rust-lang/rust-analyzer#11410
# Objective - I think our codebase is hit badly by rust-lang/rust-analyzer#11410 - None of our uses of cyclic dependencies are remotely necessary - Note that these are false positives in rust-analyzer, however it's probably easier for us to work around this - Note also that I haven't confirmed that this is causing rust-analyzer to not work very well, but it's not a bad guess. ## Solution - Remove our cyclic dependencies - Import the trick from #2851 for no-op plugin groups.
# Objective - I think our codebase is hit badly by rust-lang/rust-analyzer#11410 - None of our uses of cyclic dependencies are remotely necessary - Note that these are false positives in rust-analyzer, however it's probably easier for us to work around this - Note also that I haven't confirmed that this is causing rust-analyzer to not work very well, but it's not a bad guess. ## Solution - Remove our cyclic dependencies - Import the trick from bevyengine#2851 for no-op plugin groups.
# Objective - I think our codebase is hit badly by rust-lang/rust-analyzer#11410 - None of our uses of cyclic dependencies are remotely necessary - Note that these are false positives in rust-analyzer, however it's probably easier for us to work around this - Note also that I haven't confirmed that this is causing rust-analyzer to not work very well, but it's not a bad guess. ## Solution - Remove our cyclic dependencies - Import the trick from bevyengine#2851 for no-op plugin groups.
Get this all over the place when rust analyzer tries to understand substrate. It's really annoying that it doesn't support dev dependencies yet. The code's definitely valid rust. Given the false positives could we label it as a warning? At the moment the ui says "workspace reload required, click to reload" all the time, but when you click reload things never get any better... |
# Objective - I think our codebase is hit badly by rust-lang/rust-analyzer#11410 - None of our uses of cyclic dependencies are remotely necessary - Note that these are false positives in rust-analyzer, however it's probably easier for us to work around this - Note also that I haven't confirmed that this is causing rust-analyzer to not work very well, but it's not a bad guess. ## Solution - Remove our cyclic dependencies - Import the trick from bevyengine#2851 for no-op plugin groups.
Fixes rust-lang#9574 Fixes rust-lang#11410 `rust-analyzer` already counts all of the different targets of a crate as different crates, so it was pretty easy to just exclude dev dependencies from the dependency lists of the targets other than test, dev and bench when ingesting `cargo metadata`'s output. A similar thing is already done for build dependencies. It's possible there might be something I'm missing here, since this is quite a long-standing issue which I expected to be much more complicated to solve; but, this seems to work. The circular dependency errors that `rust-analyzer` used to throw on `wasm-bindgen` went away after switching to this patched version.
Closing in favor of #14167 |
rust-analyzer version: 2022-01-31
rustc version: rustc 1.59.0-beta.6 (0426998f5 2022-02-02) [doesn't really matter]
Setup of minimal reproducible example:
base
&ext
ext
has a dependency onbase
, uses functionality exported bybase
base
has a dev-dependency onext
, uses functionality exported byext
only in testsIssue
RA marks any imports from
base
inext
as "unresolved import", but both crates compile fine, tests succeed, etc. I've attached the example crate I used to reproduce the issue as a zip file:circular-dev-deps.zip
Loading the example crate generates two error logs entries:
I traced the error to this function:
https://github.com/rust-analyzer/rust-analyzer/blob/d3aa2579ccddd1876bc71b8e8bc965d64a77d3c6/crates/base_db/src/input.rs#L302-L321
It is fairly easy to add a field like
is_dev
to theDependency
struct and set that accordingly when generating the crate graph in project_model/workspace.rs. It should then be possible to adjustCrateGraph::find_path
so that it doesn't return a path if a circular dev dependency is found, although I haven't figured out yet how to do that.Also, I don't know what other consequences might arise later, after the circular dependency is added.
Update
When naively adjusting
CrateGraph::find_path
to simply returnNone
whenever a dev-dependency is encountered, leads to the following panic trace (so a fix might not be as straight-forward as I had hoped):The text was updated successfully, but these errors were encountered: