-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Async fn does not compile if lifetime does not appear in bounds (sometimes) #63033
Comments
Check-in from WG-async-await meeting: I agree this is a bug -- it doesn't necessarily block stabilization (no fwd compat risk) but would definitely be a good one to fix. Marking as blocking + unclear for the moment and will return to it. |
I did a bit of investigation. The error results because we have an inference variable ( |
OK, I think I see what's going on. It doesn't actually have much to do with the unused lifetime per se. What happens is this:
So thus the region solvers get in a state where Removing the unused lifetime ( Removing the type and putting it into a struct ( I'm not sure what I think is the best fix. It would be nice for the solver to pick (Interestingly, at some point at least I thought that a polonius-like approach sidesteps a lot of the challenges here-- if we had confidence that we would transition that might ease some of my concerns.) |
Now that I understand better what is happening, I don't feel this has to block stabilization -- in particular, I don't think that there is a forward compatibility risk from us improving the region inference algorithm. I don't think we would choose an algorithm that makes existing code illegal. =) As such, I'm going to mark this as Deferred. |
Here's another example of the same problem that doesn't have an unused lifetime (AFAIKT): struct Foo;
impl Foo {
async fn wat(&self, _: &'static str, _: Bar<'_>) {}
}
struct Bar<'a>(Box<dyn std::fmt::Debug + 'a>);
Removing any of the three arguments to the function allows it to compile. |
I am also affected by this bug, where having both a reference and a box as parameters to a function causes the cryptic "hidden type for trait Trait {}
async fn f<'a>(_a: &(), _b: Box<dyn Trait>) {} Is there a resolution in sight ? |
|
Ok, let me change it to something closer to what I had in my original code: trait T {}
struct S;
impl S {
async fn f(_a: &S, _b:&S, _c: Box<dyn T>) {}
} |
I think I found another example of this: trait T {}
struct L<A = Box<dyn T>> {
value: A,
}
async fn test1(l: L, s1: &str, s2: &str) {
} This example more or less represents what I met in my code (when I tried to pass a structure with a type parameter to an async function with the default value for this type parameter being a trait object), but it can be simplified by removing the default parameter assignment and passing the trait T {}
struct L<A> {
value: A,
}
async fn test1(l: L<Box<dyn T>>, s1: &str, s2: &str) {
} Curiously, if you replace use std::future::Future;
trait T {}
struct L<A> {
value: A,
}
fn test1(l: L<Box<dyn T>>, s1: &str, s2: &str) -> impl Future<Output=()> {
async {
}
} It is important to note that the trait T {}
struct L<A> {
value: A,
}
async fn test2(l: L<Box<dyn T>>, s1: &str) {
}
async fn test3(l: L<Box<dyn T>>) {
} |
@netvl 's comment is a minimal reproduction of what I ran into. I had a function |
Hmm, it is probably worth revisiting this problem now that stabilization has happened. |
Summary: walker: migrate to new futures (0.3.1). * walk.rs is not fully migrated, due to function call to `bounded_traversal_stream`, which uses old futures. * `scrub::scrub_objects`, `sizing::compression_benefit` and `validate::validate` returns `BoxFuture` instead of being a regular `async` function, due to limitation of rust issue [#63303](rust-lang/rust#63033). Reviewed By: farnz Differential Revision: D19536696 fbshipit-source-id: a0df337b86d7b067a44bf3b18834193d3f63f5dc
Any word on this? I'm getting this error as well.
Changing |
No progress or major updates. The description here is still accurate as to the root cause, but I think we don't yet know the best fix. |
this is going to become a problem now that #72459 is merged. It makes it impossible to implement consider pub struct Request<'a> {
...
}
impl<'a> Request<'a> {
async fn send(self) -> Result<(), Error> {
...
}
}
// does not compile
// "cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements"
impl<'a> IntoFuture for Request<'a> {
type Output = Result<(), Error>;
type Future = impl Future<Output = Self::Output>;
fn into_future(self) -> Self::Future {
self.send()
}
}
// does not compile
// "hidden type for `impl Trait` captures lifetime that does not appear in bounds"
impl<'a> IntoFuture for Request<'a> {
type Output = Result<(), Error>;
type Future = impl Future<Output = Self::Output> + 'a;
fn into_future(self) -> Self::Future {
self.send()
}
} |
Here's another very simple example:
Removing any of the 3 parameters makes the code compile. Alternatively, removing the static lifetime of |
Previously, the tool simply had a hardcoded set of PRIMARY_CHROMOSOMES that were hardcoded to the hg38 primary chromosomes. Now, the tool has a supported set of reference genomes, namely (to start): * GRCh38NoAlt (from the NCBI) * hs37d5 (from the 1000 Genomes Project) These two genomes were selected simply because (a) GRCh38NoAlt is probably the most popular GRCh38 genome and (b) hs37d5 is the genome used for phase 2 and phase 3 of the 1000 Genomes project: a fairly popular publicly available resource and the subject of many QC papers. Introducing a reference genome into the code required multiple QC facets to be updated to use this functionality. For each of these, I chose to simply pass the reference genome to the initialization function for the facet: it's up to the facet to take what it needs from the reference genome and store it for later use (as opposed to adding a lifecycle hook injecting it). Other notable, related changes: * I include now a check at the beginning of the `qc` command to ensure that the sequences in the header of the file match the reference genome the user specified on the commmand line. In the future, I also plan to add checks that the actual FASTA file matches the specified reference genome (if provided) _and_ that the GFF file matches the specified reference genome (if provided). There were some other changes that are introduced in this changeset that, at first, don't appear directly related: * We've now moved away from using `async`/`await` for the `qc` subcommand, as there is an obscure bug that doesn't allow two generic lifetimes and one static lifetime with an `async` function. Thus, I decided to just move away from using `async`/`await` altogether, as I had been considering that regardless (we already moved away from using the lazy evaluation facilities in noodles). See issues rust-lang/rust#63033 and rust-lang/rust#99190 for more details. * In testing this code, I was running into an error where a record fell outside of the valid range of a sequence. This was annoying, so I just decided to fix it as part of this changeset. There is no other deep reason why those changes are included here.
Encountered this today. Though the original error was this, which I couldn't reproduce it in playground. async fn handle_tx(
signer_info: &CliSignerInfo,
config: &Config,
fee_payer: Arc<dyn Signer>,
no_wait: bool,
minimum_balance_for_rent_exemption: u64,
instructions: Vec<Instruction>,
) -> Result<TransactionReturnData> {
todo!()
}
use std::sync::Arc;
trait Signer {}
async fn handle_tx(
signer_info: &u8,
config: &u8,
fee_payer: Arc<dyn Signer>,
) -> Result<(), ()> {
todo!()
} Removing any of the parameters the error is gone rustc 1.66.0-nightly (57f097e 2022-10-01) |
rework min_choice algorithm of member constraints See [this comment](rust-lang#105300 (comment)) for the description of the new algorithm. Fixes rust-lang#63033 Fixes rust-lang#104639 This uses a more general algorithm than rust-lang#89056 that doesn't treat `'static` as a special case. It thus accepts more code. For example: ```rust async fn test2<'s>(_: &'s u8, _: &'_ &'s u8, _: &'_ &'s u8) {} ``` I claim it's more correct as well because it fixes rust-lang#104639. cc `@nikomatsakis` `@lqd` `@tmandry` `@eholk` `@chenyukang` `@oli-obk` r? types
We are probably hitting this: rust-lang/rust#63033 Seems like it is worth a try to upgrade to 1.69.0 Signed-off-by: Anastassios Nanos <[email protected]>
We are probably hitting this: rust-lang/rust#63033 Seems like it is worth a try to upgrade to 1.69.0 Signed-off-by: Anastassios Nanos <[email protected]>
We are probably hitting this: rust-lang/rust#63033 Seems like it is worth a try to upgrade to 1.69.0 Signed-off-by: Anastassios Nanos <[email protected]>
We are probably hitting this: rust-lang/rust#63033 Seems like it is worth a try to upgrade to 1.69.0 Signed-off-by: Anastassios Nanos <[email protected]>
We are probably hitting this: rust-lang/rust#63033 Seems like it is worth a try to upgrade to 1.69.0 Signed-off-by: Anastassios Nanos <[email protected]>
We are probably hitting this: rust-lang/rust#63033 Seems like it is worth a try to upgrade to 1.69.0 Signed-off-by: Anastassios Nanos <[email protected]>
We are probably hitting this: rust-lang/rust#63033 Seems like it is worth a try to upgrade to 1.69.0 Signed-off-by: Anastassios Nanos <[email protected]>
The underlying issue was fixed in rust 1.69.0. Our minimum supported rust is now 1.70.0 (set in azure_core), which means this workaround is no longer needed. Ref: rust-lang/rust#63033
The underlying issue was fixed in rust 1.69.0. Our minimum supported rust is now 1.70.0 (set in azure_core), which means this workaround is no longer needed. Ref: rust-lang/rust#63033
We are probably hitting this: rust-lang/rust#63033 Seems like it is worth a try to upgrade to 1.69.0 Signed-off-by: Anastassios Nanos <[email protected]>
This fails with:
I believe this should compile because:
The non-async function with the same signature does compile;
Seemingly insignificant tweaks, like adding a wrapper struct, make it compile.
Mentioning @cramertj who fixed a similar error message in #59001.
Mentioning @nikomatsakis who touched this error message in #49041 and #61775.
rustc 1.38.0-nightly (c43753f 2019-07-26)
The text was updated successfully, but these errors were encountered: