Skip to content

Avoid incorrect lifetime suggestion involving sym::anon - #148842

Open
estebank wants to merge 1 commit into
rust-lang:mainfrom
estebank:issue-142887
Open

estebank wants to merge 1 commit into
rust-lang:mainfrom
estebank:issue-142887

Conversation

@estebank

@estebank estebank commented Nov 11, 2025 •

Copy link
Copy Markdown
Contributor

Given

#!/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 {
   |                                                                    +++++++++++++

Address #142887. Needs a repro test.

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 {
   |                                                                    +++++++++++++
```
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 11, 2025
@rustbot

rustbot commented Nov 11, 2025

Copy link
Copy Markdown
Collaborator

r? @nnethercote

rustbot has assigned @nnethercote.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@nnethercote nnethercote left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a repro test.

Yes!

View changes since this review

@nnethercote nnethercote added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 11, 2025
@JayanAXHF

Copy link
Copy Markdown
Member

@estebank Hi Triage here, is there anything blocking this PRs implementation? Are you still working on this?

@estebank

Copy link
Copy Markdown
Contributor Author

@JayanAXHF I need to come up with a minimized repro case that's suitable for the test suite. I could do with an extra hand on that.

@JayanAXHF JayanAXHF added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Feb 13, 2026
@JayanAXHF

Copy link
Copy Markdown
Member

Ive added the E-needs-mcve label, hopefully the CFP works!

@rust-bors

rust-bors Bot commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #152839) made this pull request unmergeable. Please resolve the merge conflicts.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants