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

Cyclic dependency bug processing RPIT impl Trait #55634

Closed
alexreg opened this issue Nov 2, 2018 · 6 comments
Closed

Cyclic dependency bug processing RPIT impl Trait #55634

alexreg opened this issue Nov 2, 2018 · 6 comments

Comments

@alexreg
Copy link
Contributor

@alexreg alexreg commented Nov 2, 2018

trait Foo: Fn(i32) + Send {}

impl<T: ?Sized + Fn(i32) + Send> Foo for T {}

fn gives_foo() -> impl Foo {
    let f = |x| println!("{}", x);
    f
}

fn main() {
    gives_foo()(42);
}

yields

error[E0391]: cycle detected when processing `gives_foo::{{impl-Trait}}`
 --> test.rs:5:19
  |
5 | fn gives_foo() -> impl Foo {
  |                   ^^^^^^^^
  |
note: ...which requires processing `gives_foo::{{impl-Trait}}`...
 --> test.rs:5:19
  |
5 | fn gives_foo() -> impl Foo {
  |                   ^^^^^^^^
note: ...which requires processing `gives_foo::{{impl-Trait}}`...
 --> test.rs:5:19
  |
5 | fn gives_foo() -> impl Foo {
  |                   ^^^^^^^^
  = note: ...which again requires processing `gives_foo::{{impl-Trait}}`, completing the cycle
note: cycle used when processing `gives_foo`
 --> test.rs:5:1
  |
5 | fn gives_foo() -> impl Foo {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^

I originally thought this was my PR #55101 that was at fault, but I've now confirmed this bug occurs on master, so it looks like it isn't... not in the latest nightly though, as of now, so it must have been a recent PR.

CC @nikomatsakis @oli-obk

@alexreg alexreg changed the title Cyclic dependency bug evaluating RPIT impl Trait Cyclic dependency bug processing RPIT impl Trait Nov 2, 2018
@alexreg
Copy link
Contributor Author

@alexreg alexreg commented Nov 3, 2018

Okay, weirdly this is only happening when I have RUST_LOG="rustc_typeck::astconv=debug".

@oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Nov 3, 2018

Yea, the logging output might call type_of on the item to be printed. If that happens while processing type_of, you get a cycle. Not sure how to resolve that

@alexreg
Copy link
Contributor Author

@alexreg alexreg commented Nov 3, 2018

Yep I think that’s it. Hmm.

@oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Nov 4, 2018

Hmm. why does printing cause type_of to be called on the TyAnon? Can you investigate and remove the call? it should not be necessary.

@steveklabnik
Copy link
Member

@steveklabnik steveklabnik commented Jan 30, 2020

Triage: given

Okay, weirdly this is only happening when I have RUST_LOG="rustc_typeck::astconv=debug".

and how much the compiler has changed since nov of 2018 (even though that module still exists), and with no other comments, I am gonna guess that this may not reproduce, and even if it did, wouldn't affect users. So I'm gonna give it a close. @alexreg if this still reproduces for you today, please feel free to re-open.

@oli-obk oli-obk closed this Jan 31, 2020
@alexreg
Copy link
Contributor Author

@alexreg alexreg commented Feb 1, 2020

@steveklabnik I believe I figured out the cause of this while working on another PR, and solved it. (Completely forgot about this issue!) In any case, seems reasonable to close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants