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

Open
alexreg opened this issue Nov 2, 2018 · 4 comments

Comments

Projects
None yet
3 participants
@alexreg
Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor Author

commented Nov 3, 2018

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

@oli-obk

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor Author

commented Nov 3, 2018

Yep I think that’s it. Hmm.

@oli-obk

This comment has been minimized.

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.