Skip to content

fix: Don't warn on cyclic dependencies in the crate graph#21806

Open
Wilfred wants to merge 1 commit intorust-lang:masterfrom
Wilfred:dont_warn_on_cyclic_deps
Open

fix: Don't warn on cyclic dependencies in the crate graph#21806
Wilfred wants to merge 1 commit intorust-lang:masterfrom
Wilfred:dont_warn_on_cyclic_deps

Conversation

@Wilfred
Copy link
Contributor

@Wilfred Wilfred commented Mar 12, 2026

This is legal when there are dev-dependencies, and rust-analyzer itself even does this. This causes spurious warnings in several cases, such as generating SCIP for rust-analyzer:

$ cargo run --bin rust-analyzer --release -- scip .
2026-03-12T18:40:33.824092Z  WARN cyclic deps: cfg(Idx::<CrateBuilder>(21)) -> cfg(Idx::<CrateBuilder>(21)), alternative path: cfg(Idx::<CrateBuilder>(21))

In this case, the cfg crate enables its tt feature by depending on itself in dev-dependencies.

Instead, lower the log level to info.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 12, 2026
@ChayimFriedman2
Copy link
Contributor

So we will not add the dependency, right? Can't this break code?

@Veykril
Copy link
Member

Veykril commented Mar 16, 2026

We cannot fix this, the issue is this is a package cycle (not a crate dependency cycle). Cargo allows these, but rust-analyzers crate graph can't model these as that would duplicate a bunch of crates in the graph (for the dev-dependency and without. See #14167, instead of logging each cycle as warn we should log ones that the crate graph has a cycle or more I think as a warning still. Reason being that if people report related issues we do want to know at a glance from the logs if there were cycles as that can cause issues for r-a (we just can't do anything about it)

@ChayimFriedman2
Copy link
Contributor

I believe this can indeed cause issues if cyclic crates are used e.g. in tests and we can't fix that because duplicating analysis for tests will be awful.

@Wilfred
Copy link
Contributor Author

Wilfred commented Mar 16, 2026

Can't this break code?

FWIW this is only a logging change, it's not a behaviour change.

Perhaps it would make sense to downgrade self-dependency logs to info, but treat the rest as warnings?

If not, happy to abandon this PR.

@Veykril
Copy link
Member

Veykril commented Mar 16, 2026

instead of logging each cycle as warn we should log ones that the crate graph has a cycle or more I think as a warning still. Reason being that if people report related issues we do want to know at a glance from the logs if there were cycles as that can cause issues for r-a (we just can't do anything about it)

This is legal when there are dev-dependencies, and rust-analyzer
itself even does this. This causes spurious warnings in several cases,
such as generating SCIP for rust-analyzer:

```
$ cargo run --bin rust-analyzer --release -- scip .
2026-03-12T18:40:33.824092Z  WARN cyclic deps: cfg(Idx::<CrateBuilder>(21)) -> cfg(Idx::<CrateBuilder>(21)), alternative path: cfg(Idx::<CrateBuilder>(21))
```

In this case, the `cfg` crate enables its `tt` feature by depending
on itself in dev-dependencies.

Instead, lower the log level to info for self-dependencies, but still
log cycles as warnings otherwise.
@Wilfred Wilfred force-pushed the dont_warn_on_cyclic_deps branch from 1443013 to 7c77799 Compare March 16, 2026 12:02
@rustbot
Copy link
Collaborator

rustbot commented Mar 16, 2026

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.

@Wilfred
Copy link
Contributor Author

Wilfred commented Mar 16, 2026

we should log ones that the crate graph has a cycle or more

Sorry, I'm struggling to parse this. I think you mean a cycle with length two or more?

I've updated the PR assuming I've understood correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants