Missing subtyping relationship between function pointers
Open
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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