rust-lang / rust-lang/rust

Missing subtyping relationship between function pointers

Open
#142,120 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-higher-ranked A-lifetimes A-variance C-bug T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example in src/lib.rs with rustc 1.87.0 and compare the reported types at the call between hr and no_hr. Start by tracing how higher-ranked lifetimes and function-pointer subtyping are handled; done means the shown relationship is accepted consistently with the expected types.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.