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

async fn doesn't compile if it includes at least two generic lifetimes and at least one 'static lifetime #99190

Closed
Lucretiel opened this issue Jul 12, 2022 · 3 comments
Labels
A-async-await Area: Async & Await A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Lucretiel
Copy link
Contributor

I tried this code:

async fn frobnicate(_a: &str, _b: &bool, _c: &'static i32) {}

I expected to see this happen: It compiles successfully

Instead, this happened: explanation: It fails to compile with this error message:

error[[E0700]](https://doc.rust-lang.org/stable/error-index.html#E0700): hidden type for `impl Trait` captures lifetime that does not appear in bounds
 --> src/lib.rs:2:60
  |
2 | async fn frobnicate(_a: &str, _b: &bool, _c: &'static i32) {}
  |                                                            ^^
  |
  = note: hidden type `impl Future<Output = ()>` captures lifetime '_#23r

Details

This bug appears on any async function that includes at least two generic lifetimes and at least one concrete ('static) lifetime. Some additional examples:

// Broken
async fn frobnicate(_a: &str, _b: &'static bool, _c: &i32) {}
async fn frobnicate(_a: &'static str, _b: &bool, _c: &i32) {}

// Not broken, only one generic lifetime
async fn frobnicate(_a: &str, _b: &'static bool) {}
async fn frobnicate(_a: &str, _b: &'static bool, _c: &'static i32) {}

// Not broken, no static lifetime
async fn frobnicate(_a: &str, _b: &bool, _c: &i32) {}

// Broken
async fn frobnicate(_a: &str, _b: &'static bool, _c: &'static i32, _d: &String) {}
  • It doesn't appear to matter what order the lifetimes appear in, nor does it matter whether the lifetimes exist as part of a reference type (&'a T) or named type (Cow<'a, str>).
  • It doesn't matter whether or not the lifetimes are named or elided

Meta

This bug is present on stable (1.62.0), beta (1.63.0-beta.5 2022-07-10 93ef0cd), and nightly (1.64.0-nightly 2022-07-11 38b7215).

Possibly related to #63033.

Diagnostics

Separate from the compiler bug here, there seems to be a related diagnostics bug, where the compiler describes some lifetime called '_#23r without pointing it out in the message.

@Lucretiel Lucretiel added the C-bug Category: This is a bug. label Jul 12, 2022
@lqd
Copy link
Member

lqd commented Jul 14, 2022

note: if the 2 generic lifetimes are named and you relate them, then this will compile, because having one outlive the other will offer a "least choice" and be picked.

This looks to me to be #63033 indeed, and will be fixed by #89056. The tests there are virtually the same as the examples in the OP.

claymcleod added a commit to stjude-rust-labs/ngs that referenced this issue Sep 27, 2022
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.
@Jules-Bertholet
Copy link
Contributor

This was fixed in 1.69.

@fmease fmease added A-lifetimes Area: Lifetimes / regions T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-async-await Area: Async & Await and removed needs-triage-legacy labels Jan 25, 2024
@fmease
Copy link
Member

fmease commented Jan 25, 2024

All snippets now compile successfully. Closing as fixed.

@fmease fmease closed this as completed Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants