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

RA reporting ghost lifetime errors #12743

Closed
nappa85 opened this issue Jul 11, 2022 · 3 comments
Closed

RA reporting ghost lifetime errors #12743

nappa85 opened this issue Jul 11, 2022 · 3 comments

Comments

@nappa85
Copy link

nappa85 commented Jul 11, 2022

rust-analyzer version: v0.3.1115

rustc version: 1.62.0 (a8314ef7d 2022-06-27)

relevant settings: none

Randomly RA signals as error a method like:

struct Bar {
    foo: tokio::sync::OnceCell<Foo>,
}

impl Bar {
    pub async fn foo(&self, conn: &DatabaseConnection) -> Result<&Foo, Error> {
        self.foo.get_or_try_init(|| async {
                // Do something with conn to retrieve Foo from DB
            })
            .await
    }
}

Sometimes it gives an error like:

associated function was supposed to return data with lifetime `'1` but it is returning data with lifetime `'2`rustc
mod.rs(87, 15): let's call the lifetime of this reference `'2`
mod.rs(86, 9): let's call the lifetime of this reference `'1`
lifetime may not live long enough
associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`rustc
mod.rs(86, 9): let's call the lifetime of this reference `'1`
mod.rs(87, 15): let's call the lifetime of this reference `'2`

cargo check doesn't complains about it, in facts code builds and run correctly.

I've also tried to satisfy RA requests, like that:

impl Bar {
    pub async fn foo<'a>(&'a self, conn: &DatabaseConnection) -> Result<&'a Foo, Error> {
        self.foo.get_or_try_init(|| async {
                // Do something with conn to retrieve Foo from DB
            })
            .await
    }
}

Sometimes it gives an error like:

associated function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'1`rustc
mod.rs(87, 15): let's call the lifetime of this reference `'1`
mod.rs(85, 30): lifetime `'a` defined here
lifetime may not live long enough
associated function was supposed to return data with lifetime `'1` but it is returning data with lifetime `'a`rustc
mod.rs(85, 30): lifetime `'a` defined here
mod.rs(87, 15): let's call the lifetime of this reference `'1`

Sometimes I save the file and got no errors at all...

@veber-alex
Copy link
Contributor

This looks like Rust bug rust-lang/rust#98890
So it's not an issue in RA.

@flodiebold
Copy link
Member

Yes, RA doesn't come up with lifetime errors on its own, so these have to be coming from rustc.

@flodiebold flodiebold closed this as not planned Won't fix, can't repro, duplicate, stale Jul 11, 2022
@nappa85
Copy link
Author

nappa85 commented Jul 11, 2022

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants