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

Remove identity_future indirection/hack #104826

Closed
Swatinem opened this issue Nov 24, 2022 · 3 comments · Fixed by #104833
Closed

Remove identity_future indirection/hack #104826

Swatinem opened this issue Nov 24, 2022 · 3 comments · Fixed by #104833
Labels
A-borrow-checker Area: The borrow checker A-coroutines Area: Coroutines C-bug Category: This is a bug.

Comments

@Swatinem
Copy link
Contributor

While working on #104321, creating an async generator directly lead to E0720 and E0700 errors.

The "solution" was to put the async generator through an identity function:

pub const fn identity_future<O, Fut: Future<Output = O>>(f: Fut) -> Fut { f }

This "magically" solves / hides those errors, but should ideally not be necessary.

Full Error output
---- [ui] src/test/ui/impl-trait/in-trait/default-body-with-rpit.rs stdout ----

error: test compilation failed although it shouldn't!
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/impl-trait/in-trait/default-body-with-rpit.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/impl-trait/in-trait/default-body-with-rpit" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/impl-trait/in-trait/default-body-with-rpit/auxiliary" "--edition=2021"
stdout: none
--- stderr -------------------------------
error: concrete type differs from previous defining opaque type use
   |
LL |         ""
LL |         ""
   |         ^^ expected `impl Debug`, got `&'static str`
note: previous use here
  --> /checkout/src/test/ui/impl-trait/in-trait/default-body-with-rpit.rs:10:39
   |
   |
LL |       async fn baz(&self) -> impl Debug {
LL | |         ""
LL | |     }
Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-unknown-linux-gnu
   | |_____^
   | |_____^

error[E0720]: cannot resolve opaque type
  --> /checkout/src/test/ui/impl-trait/in-trait/default-body-with-rpit.rs:10:28
   |
LL |     async fn baz(&self) -> impl Debug {
   |                            ^^^^^^^^^^ cannot resolve opaque type
   |
   = note: these returned values have a concrete "never" type
   = help: this error will resolve once the item's body returns a concrete type
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0720`.
------------------------------------------
------------------------------------------


---- [ui] src/test/ui/regions/issue-72051-member-region-hang.rs stdout ----

error: test compilation failed although it shouldn't!
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/regions/issue-72051-member-region-hang.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/regions/issue-72051-member-region-hang" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/regions/issue-72051-member-region-hang/auxiliary" "--edition=2018"
stdout: none
--- stderr -------------------------------
error[E0700]: hidden type for `impl Future<Output = ()>` captures lifetime that does not appear in bounds
   |
   |
LL | pub async fn query<'a>(_: &(), _: &(), _: (&(dyn std::any::Any + 'a),) ) {}
   |                    |
   |                    |
   |                    hidden type `impl Future<Output = ()>` captures the lifetime `'a` as defined here
error: aborting due to previous error

For more information about this error, try `rustc --explain E0700`.
------------------------------------------
------------------------------------------


---- [ui] src/test/ui/self/self_lifetime-async.rs stdout ----

error: test compilation failed although it shouldn't!
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/self/self_lifetime-async.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/self/self_lifetime-async" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/self/self_lifetime-async/auxiliary" "--edition=2018"
stdout: none
--- stderr -------------------------------
error[E0700]: hidden type for `impl Future<Output = &'a ()>` captures lifetime that does not appear in bounds
   |
   |
LL |     async fn bar<'a>(self: &Alias, arg: &'a ()) -> &() { arg }
   |
   |
   = note: hidden type `impl Future<Output = &'a ()>` captures lifetime '_#17r
error: aborting due to previous error

For more information about this error, try `rustc --explain E0700`.
------------------------------------------
@Swatinem Swatinem added the C-bug Category: This is a bug. label Nov 24, 2022
@bjorn3 bjorn3 added A-borrow-checker Area: The borrow checker and removed A-borrow-checker Area: The borrow checker labels Nov 24, 2022
@oli-obk oli-obk added A-borrow-checker Area: The borrow checker A-coroutines Area: Coroutines labels Nov 24, 2022
@Swatinem
Copy link
Contributor Author

I have a WIP for this in #104833 that I keep rebasing every now and then.

It looks like the E0700 error would be fixed by #105300,
and the E0720 was also gone at some point, possible fixed by #105255 which was then reverted from 1.67.

@compiler-errors
Copy link
Member

@Swatinem, if the E0720 is your only blocker, I can look into fixing it -- ping me if so. That's only triggered on code that's unstable currently -- it might get fixed by some changes I have in #106527, or I'd probably be able to find an alternative fix 🤔

Side-note: Currently your branch in #104833 ICEs because it's not using HIR ids correctly, I think? Could you look into that? It would be really great if we could get rid of this hack (it would help me be able to finish a fix for #106527, for example).

@Swatinem
Copy link
Contributor Author

Ah I see, looks like when I touched clippy at all, it means I need to fix it completely. But it looks like that would even improve on some clippy issues as well, hurray.

it might get fixed by some changes I have in #106527, or I'd probably be able to find an alternative fix

Do you mean to say the PRs are mutually dependent?

Either way, fixing all the tools will take me some time. I will jump on zulip if I am stuck anywhere and reach out for help.

@bors bors closed this as completed in 669e751 Mar 14, 2023
saethlin pushed a commit to saethlin/miri that referenced this issue Mar 15, 2023
…rors

Remove `identity_future` indirection

This was previously needed because the indirection used to hide some unexplained lifetime errors, which it turned out were related to the `min_choice` algorithm.

Removing the indirection also solves a couple of cycle errors, large moves and makes async blocks support the `#[track_caller]`annotation.

Fixes rust-lang/rust#104826.
flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue Mar 24, 2023
…rors

Remove `identity_future` indirection

This was previously needed because the indirection used to hide some unexplained lifetime errors, which it turned out were related to the `min_choice` algorithm.

Removing the indirection also solves a couple of cycle errors, large moves and makes async blocks support the `#[track_caller]`annotation.

Fixes rust-lang/rust#104826.
thomcc pushed a commit to tcdi/postgrestd that referenced this issue Jun 1, 2023
…rors

Remove `identity_future` indirection

This was previously needed because the indirection used to hide some unexplained lifetime errors, which it turned out were related to the `min_choice` algorithm.

Removing the indirection also solves a couple of cycle errors, large moves and makes async blocks support the `#[track_caller]`annotation.

Fixes rust-lang/rust#104826.
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 20, 2024
…rors

Remove `identity_future` indirection

This was previously needed because the indirection used to hide some unexplained lifetime errors, which it turned out were related to the `min_choice` algorithm.

Removing the indirection also solves a couple of cycle errors, large moves and makes async blocks support the `#[track_caller]`annotation.

Fixes rust-lang/rust#104826.
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
…rors

Remove `identity_future` indirection

This was previously needed because the indirection used to hide some unexplained lifetime errors, which it turned out were related to the `min_choice` algorithm.

Removing the indirection also solves a couple of cycle errors, large moves and makes async blocks support the `#[track_caller]`annotation.

Fixes rust-lang/rust#104826.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker A-coroutines Area: Coroutines C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants