Skip to content

Clean up & allow function pointers to be compared for equality natively #14719

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

Closed
wants to merge 2 commits into from

Conversation

huonw
Copy link
Member

@huonw huonw commented Jun 7, 2014

Clean up & allow function pointers to be compared for equality natively

Fixes #13385.

See commits for details.

huonw added 2 commits June 7, 2014 22:14
Previously `extern` functions up to arity 5 had `PartialEq`
implementations in libcore, but this doesn't handle comparing against
`unsafe` functions, or larger arity functions.

Fixes rust-lang#13385.
@alexcrichton
Copy link
Member

This is a change to the language, so it should be discussed a bit before merging. This also may have surprising semantics with cross-crate generics:

// foo.rs
pub fn foo<T>() -> T { fail!() }
pub fn get_foo() -> fn() -> int { foo::<int> }

// bar.rs
extern crate foo;
fn main() {
    println!("{}", foo::foo::<int> == foo::get_foo());
}

I believe that the way we monomorphize will cause the program to print false, which may go against what some people expect. Additionally, this also may apply to inlined functions

// foo.rs
#[inline]
pub fn foo() -> int { 0 }
pub fn get_foo() -> fn() -> int { foo }

// bar.rs
extern crate foo;
fn main() {
    println!("{}", foo::foo == foo::get_foo());
}

I'm not entirely certain what this will print, but I think it has a likely chance of printing false.

I suppose it depends how we want to spec this feature whether these cases make sense or not (this should be considered, though).

@huonw
Copy link
Member Author

huonw commented Jun 8, 2014

Good point, maybe this should be restricted to just extern functions.

FWIW, If this is deemed to require an RFC, I'm not going to write it... I'm just a code monkey. :P

cc @jdm @Ms2ger

@alexcrichton
Copy link
Member

Closing due to inactivity. This seems like a good idea in theory, but it would be nice to spec what happens in the situations I'm worried about.

@huonw huonw deleted the fn-eq branch December 4, 2014 02:04
flip1995 pushed a commit to flip1995/rust that referenced this pull request May 15, 2025
Closes rust-lang/rust-clippy#14685

changelog: [`manual_slice_fill`] fix FP on `IndexMut` overload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't compare unsafe function pointers
2 participants