rust-lang / rust-lang/rust

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

Open
#121,830 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug P-medium regression-from-stable-to-stable T-compiler T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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: https://github.com/rust-lang/rust/compare/c475e2303b551d726307c646181e0677af1e0069...878c8a2a62d49ca5c454547ad67290a1df746cb5
regressed commit: https://github.com/rust-lang/rust/commit/878c8a2a62d49ca5c454547ad67290a1df746cb5 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

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 failure from src/lib.rs using the shown Rust code, then inspect the regressed commit in the provided comparison range. Use cargo bisect-rustc --start=2024-02-28 --end=2024-03-01 if needed to confirm the boundary. Done means the example compiles again without the E0308 error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.