Skip to content

Commit 7509c14

Browse files
fmeasegitbot
authored and
gitbot
committed
Rollup merge of rust-lang#118833 - Urgau:lint_function_pointer_comparisons, r=cjgillot
Add lint against function pointer comparisons This is kind of a follow-up to rust-lang#117758 where we added a lint against wide pointer comparisons for being ambiguous and unreliable; well function pointer comparisons are also unreliable. We should IMO follow a similar logic and warn people about it. ----- ## `unpredictable_function_pointer_comparisons` *warn-by-default* The `unpredictable_function_pointer_comparisons` lint checks comparison of function pointer as the operands. ### Example ```rust fn foo() {} let a = foo as fn(); let _ = a == foo; ``` ### Explanation Function pointers comparisons do not produce meaningful result since they are never guaranteed to be unique and could vary between different code generation units. Furthermore different function could have the same address after being merged together. ---- This PR also uplift the very similar `clippy::fn_address_comparisons` lint, which only linted on if one of the operand was an `ty::FnDef` while this PR lints proposes to lint on all `ty::FnPtr` and `ty::FnDef`. ```@rustbot``` labels +I-lang-nominated ~~Edit: Blocked on rust-lang/libs-team#323 being accepted and it's follow-up pr~~
2 parents 01c9133 + 29b0aa5 commit 7509c14

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

core/tests/ptr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ fn test_const_nonnull_new() {
304304
#[test]
305305
#[cfg(unix)] // printf may not be available on other platforms
306306
#[allow(deprecated)] // For SipHasher
307+
#[cfg_attr(not(bootstrap), allow(unpredictable_function_pointer_comparisons))]
307308
pub fn test_variadic_fnptr() {
308309
use core::ffi;
309310
use core::hash::{Hash, SipHasher};

0 commit comments

Comments
 (0)