Skip to content

query cycle: cycle detected when checking effective visibilities #119346

Closed
@matthiaskrgr

Description

@matthiaskrgr

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

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsI-cycleIssue: A query cycle occurred while none was expectedT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions