Skip to content

unpredictable_function_pointer_comparisons doesn't lint against Option<fn()> #134527

Closed
@kornelski

Description

@kornelski
Contributor

In C FFI it's very common to use Option<fn()> for callbacks, but the lint #118833 doesn't fire when Options of function pointers are compared:

unsafe extern "C" fn func() {}

type FnPtr = unsafe extern "C" fn();

fn main() {
    assert_eq!(Some::<FnPtr>(func), Some(func as unsafe extern "C" fn()));
}

This pattern is used in: https://github.com/ImageOptim/mozjpeg-rust/blob/cff5aad77c726c11f460baefc348c7279d0ee647/src/readsrc.rs#L136

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Dec 19, 2024
Urgau

Urgau commented on Dec 19, 2024

@Urgau
Member

Looks reasonable to me. Opened #134536

self-assigned this
on Dec 19, 2024
added
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Dec 19, 2024
added a commit that references this issue on Dec 21, 2024

Rollup merge of rust-lang#134586 - Urgau:fn-ptr-lint-option, r=compil…

b7ac8d7
added a commit that references this issue on Dec 21, 2024
added a commit that references this issue on Jun 12, 2025

Rollup merge of rust-lang#134536 - Urgau:fn-ptr-option, r=compiler-er…

5f6a730
added 2 commits that reference this issue on Jun 12, 2025

Rollup merge of rust-lang#134536 - Urgau:fn-ptr-option, r=compiler-er…

b0553b3

Rollup merge of rust-lang#134536 - Urgau:fn-ptr-option, r=compiler-er…

ae76150
added a commit that references this issue on Jun 13, 2025

1 remaining item

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @kornelski@Urgau@rustbot

    Issue actions

      unpredictable_function_pointer_comparisons doesn't lint against Option<fn()> · Issue #134527 · rust-lang/rust