Skip to content
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

Cycle error when combining RPITIT, generic bounds equality, and lifetimes #122019

Closed
jhpratt opened this issue Mar 5, 2024 · 0 comments · Fixed by #122027
Closed

Cycle error when combining RPITIT, generic bounds equality, and lifetimes #122019

jhpratt opened this issue Mar 5, 2024 · 0 comments · Fixed by #122027
Assignees
Labels
C-bug Category: This is a bug. F-return_position_impl_trait_in_trait `#![feature(return_position_impl_trait_in_trait)]` I-cycle Issue: A query cycle occurred while none was expected T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jhpratt
Copy link
Member

jhpratt commented Mar 5, 2024

Minimal example (playground):

pub trait Foo<'a> {
    type Assoc;

    fn demo<T>(other: T) -> impl Foo<'a, Assoc = Self::Assoc>
    where
        T: Foo<'a, Assoc = core::convert::Infallible>;
}

outputs

error[E0391]: cycle detected when computing generics of `Foo::demo::{opaque#0}`
 --> src/lib.rs:4:29
  |
4 |     fn demo<T>(other: T) -> impl Foo<'a, Assoc = Self::Assoc>
  |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: ...which requires computing generics of `Foo::demo`...
 --> src/lib.rs:4:5
  |
4 | /     fn demo<T>(other: T) -> impl Foo<'a, Assoc = Self::Assoc>
5 | |     where
6 | |         T: Foo<'a, Assoc = core::convert::Infallible>;
  | |______________________________________________________^
note: ...which requires looking up a named region...
 --> src/lib.rs:4:5
  |
4 | /     fn demo<T>(other: T) -> impl Foo<'a, Assoc = Self::Assoc>
5 | |     where
6 | |         T: Foo<'a, Assoc = core::convert::Infallible>;
  | |______________________________________________________^
note: ...which requires resolving lifetimes...
 --> src/lib.rs:4:5
  |
4 | /     fn demo<T>(other: T) -> impl Foo<'a, Assoc = Self::Assoc>
5 | |     where
6 | |         T: Foo<'a, Assoc = core::convert::Infallible>;
  | |______________________________________________________^
note: ...which requires collecting associated items of `Foo`...
 --> src/lib.rs:1:1
  |
1 | pub trait Foo<'a> {
  | ^^^^^^^^^^^^^^^^^
note: ...which requires collecting associated items or fields of `Foo`...
 --> src/lib.rs:1:1
  |
1 | pub trait Foo<'a> {
  | ^^^^^^^^^^^^^^^^^
note: ...which requires creating associated items for impl trait in trait returned by `Foo::demo`...
 --> src/lib.rs:4:5
  |
4 | /     fn demo<T>(other: T) -> impl Foo<'a, Assoc = Self::Assoc>
5 | |     where
6 | |         T: Foo<'a, Assoc = core::convert::Infallible>;
  | |______________________________________________________^
note: ...which requires creates the associated item corresponding to the opaque type `Foo::demo::{opaque#0}`...
 --> src/lib.rs:4:29
  |
4 |     fn demo<T>(other: T) -> impl Foo<'a, Assoc = Self::Assoc>
  |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: ...which again requires computing generics of `Foo::demo::{opaque#0}`, completing the cycle
note: cycle used when collecting item types in top-level module
 --> src/lib.rs:1:1
  |
1 | / pub trait Foo<'a> {
2 | |     type Assoc;
3 | |
4 | |     fn demo<T>(other: T) -> impl Foo<'a, Assoc = Self::Assoc>
5 | |     where
6 | |         T: Foo<'a, Assoc = core::convert::Infallible>;
7 | | }
  | |_^
  = 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

In the example, the implementation is irrelevant. The definition itself is the cause for error. Removing either the lifetime or the Assoc = Infallible results in successful compilation as expected.

I don't understand why it's causing a cycle error, but intuitively I don't see why it should be. Introducing an InfallibleFoo trait with a blanket implementation is a possible workaround and what I'll be doing while the issue exists.

@jhpratt jhpratt added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. F-return_position_impl_trait_in_trait `#![feature(return_position_impl_trait_in_trait)]` I-cycle Issue: A query cycle occurred while none was expected labels Mar 5, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 5, 2024
@jhpratt jhpratt removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 5, 2024
@compiler-errors compiler-errors self-assigned this Mar 5, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 6, 2024
…astorino

Uplift some feeding out of `associated_type_for_impl_trait_in_impl` and into queries

This PR moves the `type_of` and `generics_of` query feeding out of `associated_type_for_impl_trait_in_impl`, since eagerly feeding results in query cycles due to a subtle interaction with `resolve_bound_vars`.

Fixes rust-lang#122019

r? spastorino
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 6, 2024
…astorino

Uplift some feeding out of `associated_type_for_impl_trait_in_impl` and into queries

This PR moves the `type_of` and `generics_of` query feeding out of `associated_type_for_impl_trait_in_impl`, since eagerly feeding results in query cycles due to a subtle interaction with `resolve_bound_vars`.

Fixes rust-lang#122019

r? spastorino
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 6, 2024
…astorino

Uplift some feeding out of `associated_type_for_impl_trait_in_impl` and into queries

This PR moves the `type_of` and `generics_of` query feeding out of `associated_type_for_impl_trait_in_impl`, since eagerly feeding results in query cycles due to a subtle interaction with `resolve_bound_vars`.

Fixes rust-lang#122019

r? spastorino
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 6, 2024
…astorino

Uplift some feeding out of `associated_type_for_impl_trait_in_impl` and into queries

This PR moves the `type_of` and `generics_of` query feeding out of `associated_type_for_impl_trait_in_impl`, since eagerly feeding results in query cycles due to a subtle interaction with `resolve_bound_vars`.

Fixes rust-lang#122019

r? spastorino
@bors bors closed this as completed in 34cffae Mar 7, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 7, 2024
Rollup merge of rust-lang#122027 - compiler-errors:rpitit-cycle, r=spastorino

Uplift some feeding out of `associated_type_for_impl_trait_in_impl` and into queries

This PR moves the `type_of` and `generics_of` query feeding out of `associated_type_for_impl_trait_in_impl`, since eagerly feeding results in query cycles due to a subtle interaction with `resolve_bound_vars`.

Fixes rust-lang#122019

r? spastorino
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-return_position_impl_trait_in_trait `#![feature(return_position_impl_trait_in_trait)]` I-cycle Issue: A query cycle occurred while none was expected T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
3 participants