Skip to content

Coercing higher-ranked function definitions to non-hr function pointers doesn't work  #145572

@BenjaminBrienen

Description

@BenjaminBrienen

I tried this code:

fn foo() {
    let _: [fn(_); 2] = [x, y];
}
fn x(_: &str) {
    todo!()
}
fn y(_: &str) {
    todo!()
}

I expected to see this happen: compiles

Instead, this happened:

error[E0308]: mismatched types
 --> src/lib.rs:2:29
  |
2 |     let _: [fn(_); 2] = [x, y];
  |                             ^ one type is more general than the other
  |
  = note: expected fn pointer `fn(&_)`
                found fn item `for<'a> fn(&'a _) {y}`

For more information about this error, try `rustc --explain E0308`.

Meta

rustc --version --verbose:

stable 1.89

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-coercionsArea: implicit and explicit `expr as Type` coercionsA-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)C-enhancementCategory: An issue proposing an enhancement or a PR with one.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