Skip to content

Unclear TAIT error on auto trait solving #107320

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

Open
oli-obk opened this issue Jan 26, 2023 · 3 comments
Open

Unclear TAIT error on auto trait solving #107320

oli-obk opened this issue Jan 26, 2023 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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.

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Jan 26, 2023

I am trying to use TAIT to poll a future constructed by an async fn, but running into this error, I am unsure where the issue exactly is, would appreciate any guidance
Example Code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=b2a9d6f2493a79743f66e7852aeca81a

Error

error[[E0391]](https://doc.rust-lang.org/nightly/error-index.html#E0391): cycle detected when computing type of `BarFuture::{opaque#0}`
  --> src/lib.rs:7:18
   |
7  | type BarFuture = impl Future<Output = usize> + Send + Sync + 'static;
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: ...which requires type-checking `<impl at src/lib.rs:17:1: 17:11>::bar_project`...
  --> src/lib.rs:23:40
   |
23 |         let bar: &mut BarFuture = &mut self.bar;
   |                                        ^^^^
   = note: ...which requires evaluating trait selection obligation `core::pin::Pin<&'a mut State>: core::ops::deref::DerefMut`...
   = note: ...which again requires computing type of `BarFuture::{opaque#0}`, completing the cycle
note: cycle used when checking item types in top-level module
  --> src/lib.rs:1:1
   |
1  | / #![feature(type_alias_impl_trait)]
2  | |
3  | | [use std::future::Future;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=b2a9d6f2493a79743f66e7852aeca81a#)
4  | | [use std::pin::Pin;](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=b2a9d6f2493a79743f66e7852aeca81a#)
...  |
33 | |     }
34 | | }
   | |_^

Originally posted by @dignifiedquire in #86733 (comment)

We should make cycle errors due to opaque types tell the user about the fact that they can control what's in the defining scope and what isn't

@oli-obk
Copy link
Contributor Author

oli-obk commented Jan 26, 2023

Unfortunately cycle errors are some of the hardest to debug. Usually cycle errors with TAITs come from auto traits like Send and Sync. In this case, due to the involvement of Pin I am guessing it's about the Unpin auto trait. Basically in order to prove that Pin<&'a mut State>: DerefMut we need to prove that State: Unpin. You can prove this by adding Unpin to the list of traits on your TAIT, but then you'll just run into new errors. These may be clearer to you.

Either way, I'll look into improving these cycle error.

@oli-obk oli-obk changed the title Unclear TAIT error Unclear TAIT error on auto trait solving Jan 26, 2023
@oli-obk oli-obk added A-diagnostics Area: Messages for errors, warnings, and lints F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` labels Jan 26, 2023
@oli-obk oli-obk moved this to Can do after stabilization in type alias impl trait stabilization Jan 26, 2023
@dignifiedquire
Copy link

You can prove this by adding Unpin to the list of traits on your TAIT, but then you'll just run into new errors.

I believe that will not work due to the fact that the futures from async fns are !Unpin.

@oli-obk
Copy link
Contributor Author

oli-obk commented Jan 27, 2023

Ah right, you want !Pin. Either way, the way to break the cycle is to change what is in the defining scope: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=d6eab067c3324f59b718b8a29892f02b

@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 24, 2023
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 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.
Projects
Status: Can do after stabilization
Development

No branches or pull requests

3 participants