rust-lang / rust-lang/rust

query cycles could be handled more like ICEs

Open
#119,321 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics A-query-system C-discussion metabug T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

from https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/recent-ish.20nightly.20regression.20wrt.20Freeze

Sometimes the compiler blurps out something like error[E0391]: cycle detected when XYZ

yay: the compiler saved itself from going in circles infinitely because it noticed it was trying to compute something self-referential

nay: we SHOULD have had a proper diagnostic earlier in which the compiler errors out and explains the user why the self-referential thing they are trying to do is not going to work out instead of just throwing a "oops, query cycle" in their face.

If we encounter such a query cycle, we should tell users to report it a diagnostic bug.
Maybe we can also improve the spans of the E0391 a bit.

error[E0391]: cycle detected when looking up late bound vars
 --> /home/matthias/vcs/github/rust_misc_stuff/tests/ui/traits/inheritance/auxiliary/icemaker_omni/BE190CEE104A225CD4B33CFB5FA41C069766D54BE3319CDCF10B5BCBEC24AD11.rs:4:1
  |
4 | pub trait MyNum : Add<Output=Self> + MyNum<Output=Self> + Mul<Output=Self> + PartialEq + Clone {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: ...which requires resolving lifetimes...
 --> /home/matthias/vcs/github/rust_misc_stuff/tests/ui/traits/inheritance/auxiliary/icemaker_omni/BE190CEE104A225CD4B33CFB5FA41C069766D54BE3319CDCF10B5BCBEC24AD11.rs:4:1
  |
4 | pub trait MyNum : Add<Output=Self> + MyNum<Output=Self> + Mul<Output=Self> + PartialEq + Clone {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires computing the super traits of `MyNum` with associated type name `Output`...
 --> /home/matthias/vcs/github/rust_misc_stuff/tests/ui/traits/inheritance/auxiliary/icemaker_omni/BE190CEE104A225CD4B33CFB5FA41C069766D54BE3319CDCF10B5BCBEC24AD11.rs:4:1
  |
4 | pub trait MyNum : Add<Output=Self> + MyNum<Output=Self> + Mul<Output=Self> + PartialEq + Clone {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: ...which again requires looking up late bound vars, completing the cycle
note: cycle used when computing the super predicates of `MyNum`
 --> /home/matthias/vcs/github/rust_misc_stuff/tests/ui/traits/inheritance/auxiliary/icemaker_omni/BE190CEE104A225CD4B33CFB5FA41C069766D54BE3319CDCF10B5BCBEC24AD11.rs:4:1
  |
4 | pub trait MyNum : Add<Output=Self> + MyNum<Output=Self> + Mul<Output=Self> + PartialEq + Clone {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

error: aborting due to 3 previous errors

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the query and queries sections of the Rust compiler development documentation linked in the issue, then reproduce the shown E0391 cycle involving MyNum. Determine how cycle diagnostics should distinguish compiler bugs from user errors and whether their spans can be improved. Done means the cycle produces a more actionable diagnostic, or explicitly directs users to report a diagnostic bug, with improved spans where possible.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.