Skip to content

error: X does not live long enough doesn't provide enough context #111852

Open
@frederikhors

Description

@frederikhors

REPRODUCTION: https://www.rustexplorer.com/b/oe3uh4

error:

error: `impl Executor` does not live long enough
   --> src/main.rs:136:5
    |
136 | /     async move {
137 | |         dbg!("I'm:", user);
138 | |
139 | |         let mut store = store.unwrap_or_default();
...   |
169 | |     }
170 | |     .boxed()
    | |____________^

Some code:

fn query_teams<'a>(
    user: &'a str,
    db: &'a mut impl Executor,
    store: Option<Store>,
    with_player: bool,
) -> BoxFuture<'a, Store> {
    async move {
        dbg!("I'm:", user);

        let mut store = store.unwrap_or_default();

        let mut query = sqlx::QueryBuilder::new(r#"SELECT "teams".*" FROM "teams"#);

        let teams = query
            .build_query_as::<Team>()
            .fetch_all(db.as_executor())
            .await
            .unwrap();

        for team in teams {
            store.teams.insert(team.id.to_string(), team);
        }

        if with_player {
            store = query_players(user, db, Some(store), false).await;
        }

        store
    }
    .boxed()
}
error: `impl Executor` does not live long enough
   --> src/main.rs:136:5
    |
136 | /     async move {
137 | |         dbg!("I'm:", user);
138 | |
139 | |         let mut store = store.unwrap_or_default();
...   |
169 | |     }
170 | |     .boxed()
    | |____________^

Meta

rustc 1.69.0 (84c898d65 2023-04-16)
binary: rustc
commit-hash: 84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc
commit-date: 2023-04-16
host: x86_64-pc-windows-msvc
release: 1.69.0
LLVM version: 15.0.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-GATsArea: Generic associated types (GATs)A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions