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

query cycle: cycle detected when checking effective visibilities #119346

Closed
matthiaskrgr opened this issue Dec 27, 2023 · 1 comment · Fixed by #119506
Closed

query cycle: cycle detected when checking effective visibilities #119346

matthiaskrgr opened this issue Dec 27, 2023 · 1 comment · Fixed by #119506
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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

@matthiaskrgr
Copy link
Member

Code

trait Marker {}
impl Marker for u32 {}

trait MyTrait {
    fn foo(&self) -> impl Marker;
}

struct Outer;

impl MyTrait for Outer {
    fn foo(&self) -> impl Marker {
        42
    }
}

impl dyn MyTrait {
    fn other(&self) -> impl Marker {
        MyTrait::foo(&self)
    }
}

fn main() {}

Current output

error[E0277]: the trait bound `&dyn MyTrait: MyTrait` is not satisfied
  --> 38261B4E22E3BC8FEAD23C85E4CAE47D3F2B59CC950435EE3E08426A57F8BBE3.rs:18:22
   |
18 |         MyTrait::foo(&self)
   |         ------------ ^^^^^ the trait `MyTrait` is not implemented for `&dyn MyTrait`
   |         |
   |         required by a bound introduced by this call
   |
   = help: the trait `MyTrait` is implemented for `Outer`

error[E0391]: cycle detected when checking effective visibilities
   |
note: ...which requires computing type of `<impl at 38261B4E22E3BC8FEAD23C85E4CAE47D3F2B59CC950435EE3E08426A57F8BBE3.rs:16:1: 16:17>::other::{opaque#0}`...
  --> 38261B4E22E3BC8FEAD23C85E4CAE47D3F2B59CC950435EE3E08426A57F8BBE3.rs:17:24
   |
17 |     fn other(&self) -> impl Marker {
   |                        ^^^^^^^^^^^
note: ...which requires computing type of opaque `<impl at 38261B4E22E3BC8FEAD23C85E4CAE47D3F2B59CC950435EE3E08426A57F8BBE3.rs:16:1: 16:17>::other::{opaque#0}`...
  --> 38261B4E22E3BC8FEAD23C85E4CAE47D3F2B59CC950435EE3E08426A57F8BBE3.rs:17:24
   |
17 |     fn other(&self) -> impl Marker {
   |                        ^^^^^^^^^^^
note: ...which requires type-checking `<impl at 38261B4E22E3BC8FEAD23C85E4CAE47D3F2B59CC950435EE3E08426A57F8BBE3.rs:16:1: 16:17>::other`...
  --> 38261B4E22E3BC8FEAD23C85E4CAE47D3F2B59CC950435EE3E08426A57F8BBE3.rs:17:5
   |
17 |     fn other(&self) -> impl Marker {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: ...which again requires checking effective visibilities, completing the cycle
note: cycle used when checking that `<impl at 38261B4E22E3BC8FEAD23C85E4CAE47D3F2B59CC950435EE3E08426A57F8BBE3.rs:16:1: 16:17>` is well-formed
  --> 38261B4E22E3BC8FEAD23C85E4CAE47D3F2B59CC950435EE3E08426A57F8BBE3.rs:16:1
   |
16 | impl dyn MyTrait {
   | ^^^^^^^^^^^^^^^^
   = 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 2 previous errors

Some errors have detailed explanations: E0277, E0391.
For more information about an error, try `rustc --explain E0277`

Desired output

No response

Rationale and extra context

cc #119321

Other cases

No response

Anything else?

No response

@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 27, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 27, 2023
@compiler-errors compiler-errors self-assigned this Jan 1, 2024
@yuvadm
Copy link

yuvadm commented Jan 2, 2024

Is there any workaround for this issue before a patch lands?

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 5, 2024
…bject-safety-error, r=Nilstrieb

Use `resolutions(()).effective_visiblities` to avoid cycle errors in `report_object_error`

Inside of `report_object_error`, using the `effective_visibilities` query causes cycles since it calls `type_of`, which itself may call `typeck`, which may end up reporting its own object-safety errors.

Fixes rust-lang#119346
Fixes rust-lang#119502
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 5, 2024
…bject-safety-error, r=Nilstrieb

Use `resolutions(()).effective_visiblities` to avoid cycle errors in `report_object_error`

Inside of `report_object_error`, using the `effective_visibilities` query causes cycles since it calls `type_of`, which itself may call `typeck`, which may end up reporting its own object-safety errors.

Fixes rust-lang#119346
Fixes rust-lang#119502
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jan 5, 2024
…bject-safety-error, r=Nilstrieb

Use `resolutions(()).effective_visiblities` to avoid cycle errors in `report_object_error`

Inside of `report_object_error`, using the `effective_visibilities` query causes cycles since it calls `type_of`, which itself may call `typeck`, which may end up reporting its own object-safety errors.

Fixes rust-lang#119346
Fixes rust-lang#119502
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 5, 2024
…bject-safety-error, r=Nilstrieb

Use `resolutions(()).effective_visiblities` to avoid cycle errors in `report_object_error`

Inside of `report_object_error`, using the `effective_visibilities` query causes cycles since it calls `type_of`, which itself may call `typeck`, which may end up reporting its own object-safety errors.

Fixes rust-lang#119346
Fixes rust-lang#119502
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 5, 2024
…bject-safety-error, r=Nilstrieb

Use `resolutions(()).effective_visiblities` to avoid cycle errors in `report_object_error`

Inside of `report_object_error`, using the `effective_visibilities` query causes cycles since it calls `type_of`, which itself may call `typeck`, which may end up reporting its own object-safety errors.

Fixes rust-lang#119346
Fixes rust-lang#119502
@bors bors closed this as completed in 8309063 Jan 5, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 5, 2024
Rollup merge of rust-lang#119506 - compiler-errors:visibilities-for-object-safety-error, r=Nilstrieb

Use `resolutions(()).effective_visiblities` to avoid cycle errors in `report_object_error`

Inside of `report_object_error`, using the `effective_visibilities` query causes cycles since it calls `type_of`, which itself may call `typeck`, which may end up reporting its own object-safety errors.

Fixes rust-lang#119346
Fixes rust-lang#119502
@fmease fmease added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 16, 2024
@fmease fmease added the I-cycle Issue: A query cycle occurred while none was expected label Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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
5 participants