Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
kornelski opened this issue Dec 19, 2024 · 1 comment · May be fixed by #134536
Closed

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

kornelski opened this issue Dec 19, 2024 · 1 comment · May be fixed by #134536
Assignees
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug.

Comments

@kornelski
Copy link
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

@kornelski kornelski added the C-bug Category: This is a bug. label Dec 19, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 19, 2024
@Urgau
Copy link
Member

Urgau commented Dec 19, 2024

Looks reasonable to me. Opened #134536

@Urgau Urgau self-assigned this Dec 19, 2024
@Urgau Urgau added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 19, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 21, 2024
…er-errors

Also lint on option of function pointer comparisons

This PR is the first part of rust-lang#134536, ie. the linting on `Option<{fn ptr}>` in the `unpredictable_function_pointer_comparisons` lint, which isn't part of the lang nomination that the second part is going trough, and so should be able to be approved independently.

Related to rust-lang#134527
r? `@compiler-errors`
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 21, 2024
Rollup merge of rust-lang#134586 - Urgau:fn-ptr-lint-option, r=compiler-errors

Also lint on option of function pointer comparisons

This PR is the first part of rust-lang#134536, ie. the linting on `Option<{fn ptr}>` in the `unpredictable_function_pointer_comparisons` lint, which isn't part of the lang nomination that the second part is going trough, and so should be able to be approved independently.

Related to rust-lang#134527
r? `@compiler-errors`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants