Skip to content

Missing subtyping relationship between function pointers #142120

Open
@Jules-Bertholet

Description

@Jules-Bertholet

I tried this code:

fn hr(arg: &for<'a> fn(&'static &'a ())) {
    no_hr(arg)
}

fn no_hr(arg: &fn(&'static &'static ())) {
    hr(arg)
}

I expected to see this happen: It compiles. In for<'a> fn(&'static &'a ()), 'a must be 'static, so this type should be equivalent to fn(&'static &'static ()).

Instead, this happened:

error[E0308]: mismatched types
 --> src/lib.rs:6:10
  |
6 |     hr(arg)
  |        ^^^ one type is more general than the other
  |
  = note: expected reference `&for<'a> fn(&&'a ())`
             found reference `&fn(&&())`

Meta

rustc --version:

1.87.0

@rustbot label T-types A-higher-ranked A-lifetimes A-variance

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-lifetimesArea: Lifetimes / regionsA-varianceArea: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)C-bugCategory: This is a bug.T-typesRelevant to the types 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