Skip to content

Explicit non-'static lifetimes ignored in explicit closure argument types #87290

@mcy

Description

@mcy

I tried this code: https://godbolt.org/z/Pdj46T1v5

pub fn f<'a>(_: &'a i32, _: impl FnOnce(&mut &mut &'a i32)) {}

pub fn g<'a>(p: &'a i32) {
    f(p, |_: &mut &mut &'a i32| {})
}

I expected an error along the lines of "expected &mut &mut &i32, got &mut &mut &'a i32." Instead, rustc accepts this program.
The following modification does not compile with the expected error.

pub fn f<'a>(_: &'a i32, _: impl FnOnce(&mut &mut &'a i32)) {}

pub fn g<'a>(p: &'a i32) {
    f(p, |x: &mut &mut &'a i32| {
        let _: &mut &mut &'a i32 = x;
    })
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)A-lifetimesArea: Lifetimes / regionsC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions