Skip to content

unused_lifetimes warning misses unused lifetime #74165

Open
@bobbobbio

Description

@bobbobbio

I discovered an unused lifetime in my code that the compiler didn't tell me about. I was able to reduce the problem to the following snippet.

#![warn(unused_lifetimes)]

struct Foo<'a>(for<'r> fn(&'r mut Foo<'a>));

impl<'a> Foo<'a> {
    pub fn new() -> Self {
        Self(Self::a)
    }
    
    pub fn a(&mut self) {}
}

fn main() {
    let f = Foo::new();
    drop(f);
}

The lifetime 'a is unused, but the compiler doesn't complain at all. I confirmed that it still exists on stable 1.44.1 and on nightly 1.46.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.T-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