Skip to content

Confused "elided lifetime has a name" warning #143913

@abel-von

Description

@abel-von

We had some codes like below

async fn container(&self, id: &str) -> Result<&Self::Container> {

I think this is a normal case follows lifetime elision rules,

If there are multiple input lifetime positions, but one of them is &self or &mut self, the lifetime of self is assigned to all elided output lifetimes.

But we got a clippy error after we update rust to 1.85

error: elided lifetime has a name
   --> src/sandbox.rs:350:51
    |
350 |     async fn container(&self, id: &str) -> Result<&Self::Container> {
    |                        -                          ^ this elided lifetime gets resolved as `'life0`
    |                        |
    |                        lifetime `'life0` declared here
    |
    = note: `-D elided-named-lifetimes` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(elided_named_lifetimes)]`

error: could not compile `runc-sandboxer` (bin "runc-sandboxer" test) due to 1 previous error
Error: Process completed with exit code 101.

Current output

error: elided lifetime has a name
   --> src/sandbox.rs:350:51
    |
350 |     async fn container(&self, id: &str) -> Result<&Self::Container> {
    |                        -                          ^ this elided lifetime gets resolved as `'life0`
    |                        |
    |                        lifetime `'life0` declared here
    |
    = note: `-D elided-named-lifetimes` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(elided_named_lifetimes)]`

error: could not compile `runc-sandboxer` (bin "runc-sandboxer" test) due to 1 previous error
Error: Process completed with exit code 101.

Desired output

No compile error

Rationale and extra context

No response

Other cases

Rust Version

Run sudo -E $(command -v cargo) test --all-features
info: syncing channel updates for '1.85-x86_64-unknown-linux-gnu'
info: latest update on 2025-03-18, rust version 1.85.1 (4eb161250 2025-03-15)

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions