async-graphql: SimpleObject: error: lifetime may not live long enough
I got some weird error after using #[graphql(complex)]
and #[ComplexObject]
on other struct.
So the affected struct doesn’t have the “complex” thing.
I’m probably using nested ComplexObject
that uses some dataloaders.
I’ll try to make a minimal, reproducible example.
Expected Behavior
Actual Behavior
13 | #[derive(Debug, PartialEq, SimpleObject)]
| -^^^^^^^^^^^
| |
| let's call the lifetime of this reference `'2`
| let's call the lifetime of this reference `'1`
| associated function was supposed to return data with lifetime `'1` but it is returning data with lifetime `'2`
| in this derive macro expansion
|
::: /home/bbigras/.cargo/registry/src/github.com-1ecc6299db9ec823/async-graphql-derive-3.0.38/src/lib.rs:47:1
Steps to Reproduce the Problem
Specifications
- Version: 3.0.38
- Platform: NixOS 22.05 (Quokka) x86_64
- Subsystem:
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 6
- Comments: 28 (7 by maintainers)
Commits related to this issue
- Workaround for #900 — committed to danielhenrymantilla/async-graphql by danielhenrymantilla 2 years ago
- Workaround for #900 — committed to danielhenrymantilla/async-graphql by danielhenrymantilla 2 years ago
This is probably fixed now in Rust 1.62.1: https://github.com/rust-lang/rust/issues/98890
Click to see how I reached that situation
Ok, I have investigated a bit the @Bberky’s situation. They managed to reduce the issue to:
with a
cargo c
before and after that diff, on1.62.0
, triggering a lifetime error message as reported by other people in this repo. By using an intermediary expansion trick, I got the expansion ofSimpleObject
onA
to be:Click to see the expansion
From there, once that diff is applied in between
cargo check
s, I get:So the interesting part is that this does not involve
async_trait
whatsoever (I was afraid it would), and so the following part of the expansion is the one hitting the incremental compilation bug:Finally, removing
SimpleObject
altogether from the equation, we end up with the following diff in betweencargo check
s running into the incremental compilation issue:which ends up yielding the following stand-alone repro which I’ll report to rust [EDIT: done]:
In the meantime, @sunli829 (or other maintainers of this crate), you may be able to dodge the compiler limitation by using
https://docs.rs/fix-hidden-lifetime-bug
on the non-async_trait
-annotatedasync fn
s 🙂Just started getting this, can’t reliably trigger or reliably stop it from happening 😂 cargo clean temporarily fixes it as others said, perhaps something related to compilation order, or something not being recompiled?
async-graphql
andasync-graphql-axum
4.0.4
-stable-aarch64-apple-darwin
I have a simple script now for this until there is some workaround as doing
cargo clean
just takes way too long for me. The issue happens quite often for me, when the compiler complains about other things beforehand for some reason this issue pops up even though the other issues have been fixed. If your workflow consists ofcargo watch -x "run"
and having an autosave in your editor just makes this issue very common.This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
I tested my https://github.com/async-graphql/async-graphql/issues/900#issuecomment-1175787840 to confirm nightly-2022-07-23 (
rustc 1.64.0-nightly (848090dcd 2022-07-22)
) is fixed.@ControlCplusControlV you should be able to save in compile times by using that PR through a patch rather than fully disabling incremental altogether 🙂:
I was able to fix this issue by simple running
export CARGO_INCREMENTAL=0
, requires a better workstation to remain productive but it does work