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

Weird "cycle detected" error around type_alias_impl_trait and auto traits. #71153

Closed
steffahn opened this issue Apr 14, 2020 · 2 comments
Closed
Labels
A-trait-system Area: Trait system C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@steffahn
Copy link
Member

steffahn commented Apr 14, 2020

#![feature(type_alias_impl_trait)]
#![feature(optin_builtin_traits)]

auto trait Auto {}

fn b() -> Box<dyn Auto> { Box::new(c()) }

type Type = impl Sized;

fn c() -> Type {}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0391]: cycle detected when processing `Type`
  --> src/lib.rs:8:1
   |
8  | type Type = impl Sized;
   | ^^^^^^^^^^^^^^^^^^^^^^^
   |
note: ...which requires type-checking `b`...
  --> src/lib.rs:6:1
   |
6  | fn b() -> Box<dyn Auto> { Box::new(c()) }
   | ^^^^^^^^^^^^^^^^^^^^^^^
   = note: ...which requires evaluating trait selection obligation `Type: Auto`...
   = note: ...which again requires processing `Type`, completing the cycle
note: cycle used when collecting item types in top-level module
  --> src/lib.rs:1:1
   |
1  | / #![feature(type_alias_impl_trait)]
2  | | #![feature(optin_builtin_traits)]
3  | |
4  | | auto trait Auto {}
...  |
9  | |
10 | | fn c() -> Type {}
   | |_________________^

error[E0391]: cycle detected when processing `Type`
  --> src/lib.rs:8:1
   |
8  | type Type = impl Sized;
   | ^^^^^^^^^^^^^^^^^^^^^^^
   |
note: ...which requires type-checking `b`...
  --> src/lib.rs:6:1
   |
6  | fn b() -> Box<dyn Auto> { Box::new(c()) }
   | ^^^^^^^^^^^^^^^^^^^^^^^
   = note: ...which again requires processing `Type`, completing the cycle
note: cycle used when collecting item types in top-level module
  --> src/lib.rs:1:1
   |
1  | / #![feature(type_alias_impl_trait)]
2  | | #![feature(optin_builtin_traits)]
3  | |
4  | | auto trait Auto {}
...  |
9  | |
10 | | fn c() -> Type {}
   | |_________________^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0391`.
error: could not compile `playground`.

To learn more, run the command again with --verbose.

@rustbot modify labels: C-bug, T-compiler, F-type_alias_impl_trait, requires-nightly, A-traits.
(Note: optin_builtin_traits only used to demonstrate that any auto trait works, for example Send.)

@rustbot rustbot added C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. requires-nightly This issue requires a nightly compiler in some way. A-trait-system Area: Trait system labels Apr 14, 2020
@taiki-e
Copy link
Member

taiki-e commented Apr 20, 2020

Looks like dup of #55997

@oli-obk
Copy link
Contributor

oli-obk commented Feb 19, 2021

Yes, it's a duplicate. Closing as such.

For anyone reaching this issue, at the time of writing this comment, the workaround is to put all defining uses into their own module together with the TAIT itself. For all further development on this, follow #55997

#![feature(type_alias_impl_trait)]
#![feature(auto_traits)]

auto trait Auto {}

fn b() -> Box<dyn Auto> { Box::new(foo::c()) }

mod foo {
    type Type = impl Sized;
    
    pub fn c() -> Type {}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Development

No branches or pull requests

4 participants