...">

Avoid incorrect lifetime suggestion involving sym::anon by estebank · Pull Request #148842 · rust-lang/rust (original) (raw)

Given ```rust #!/usr/bin/env -S cargo +nightly -Zscript -q

packag.edition = "2024"

[dependencies] rama = "0.2.0"

fn main() {}

struct Foo;

impl<S, Request: 'static> rama::Service<S, Request> for Foo { type Response = (); type Error = ();

fn serve(
    &self,
    _ctx: rama::Context<S>,
    _req: Request,
) -> impl Future<Output = Result<Self::Response, Self::Error>> {
    async { todo!() }
}

}

emit

error[E0311]: the parameter type S may not live long enough --> f20.rs:20:10 | 20 | ) -> impl Future<Output = Result<Self::Response, Self::Error>> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type impl Future<Output = Result<<Foo as Service<S, Request>>::Response, <Foo as Service<S, Request>>::Error>> will meet its required lifetime bounds... | ::: /home/gh-estebank/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rama-core-0.2.0/src/service/svc.rs:19:9 | 19 | &self, | - the parameter type S must be valid for the anonymous lifetime as defined here... | note: ...that is required by this bound --> /home/gh-estebank/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/rama-core-0.2.0/src/service/svc.rs:22:77 | 22 | ) -> impl Future<Output = Result<Self::Response, Self::Error>> + Send + '_; | ^^


without the incorrect suggestion

help: consider adding an explicit lifetime bound | 22 | ) -> impl Future<Output = Result<Self::Response, Self::Error>> where S: anon { | +++++++++++++ ```