Skip to content

error[E0308]: mismatched types expected fn pointer, found fn item #121830

Open
@dianqk

Description

@dianqk

Code

I tried this code:

pub fn foo(_: &i32, _: &i32) {}
pub const _: [for<'r> fn(&'r i32, &'r i32); 2] = [foo, foo];

I expected to see this happen: compile successfully

Instead, this happened:

error[E0308]: mismatched types
 --> src/lib.rs:3:56
  |
3 | pub const _: [for<'r> fn(&'r i32, &'r i32); 2] = [foo, foo];
  |                                                        ^^^ expected fn pointer, found fn item
  |
  = note: expected fn pointer `for<'r> fn(&'r _, &'r _)`
                found fn item `for<'a, 'b> fn(&'a _, &'b _) {foo}`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `fnitem` (lib) due to 1 previous error

Version it worked on

It most recently worked on: nightly-2024-02-29

Version with regression

searched nightlies: from nightly-2024-02-28 to nightly-2024-03-01
regressed nightly: nightly-2024-03-01
searched commit range: c475e23...878c8a2
regressed commit: 878c8a2 cc @spastorino

bisected with cargo-bisect-rustc v0.6.8

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --start=2024-02-28 --end=2024-03-01

@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions