Skip to content

Incremental compilation bug with async fn method capturing multiple lifetimes #98890

Closed
@danielhenrymantilla

Description

@danielhenrymantilla

Regression since 1.62.0

The following diff:

  struct Foo;

  impl Foo {
      async fn f(&self, _: &&()) -> &() {
          &()
      }
  }

+ enum Bar {}

if done in between cargo checks, makes the second check fail with:

error: lifetime may not live long enough
 --> src/lib.rs:5:43
  |
5 |           async fn f(&self, _: &&()) -> &() {
  |  ____________________-__________-___________^
  | |                    |          |
  | |                    |          let's call the lifetime of this reference `'2`
  | |                    let's call the lifetime of this reference `'1`
6 | |             &()
7 | |         }
  | |_________^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
  • Aside: that error is printed twice, which is also curious.

To reproduce, the following snippet fails on the Playground:

fn main(){let _=std::process::Command::new("/bin/bash").args(&["-c", concat!(r##"{
set -euo pipefail
cd $(mktemp -d)


cargo init -q --name example --lib

cat> src/lib.rs <<'EOF'
    #![allow(unused)]
    struct Foo;
    
    impl Foo {
        async fn f(&self, _: &&()) -> &() {
            &()
        }
    }
EOF

(set -x
    cargo c -q
    { set +x; echo 'enum Bar {}'; } 2>/dev/null | tee -a src/lib.rs
    cargo c -q
)


echo ✅
} 2>&1"##)]).status();}

I've reported it over #96655 to avoid defining a duplicate issue, but now that I've noticed it's a regression, I prefer to risk it being a dup than it going unnoticed.

I've also mentioned this over: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/incremental.20bug.20with.20async.20fns.20and.20lifetimes


Context

This is causing major breakage with users of async-graphql who have switched to Rust 1.62.0 or up, as showcased by:


@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.P-criticalCritical priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions