Skip to content

Commit 525e8da

Browse files
committed
Allow function pointer comparisons lint
We don't need a type ID check because constants that are compared to each other all come from the same code generation unit, so their `partial_cmp` function pointers will never differ.
1 parent 26e2888 commit 525e8da

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Diff for: src/entry/generic.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,15 @@ impl EntryConst {
153153
/// Returns [`PartialOrd::partial_cmp`] ordering if `<` or `>, falling back
154154
/// to comparing [`ToString::to_string`] otherwise.
155155
pub(crate) fn cmp_name(&self, other: &Self) -> Ordering {
156+
// SAFETY: If both constants have the same `partial_cmp` function
157+
// pointer, they are safely comparable. In the context of how this
158+
// method is used, it is because the constants are of the same type.
159+
//
160+
// We don't need a type ID check because constants that are compared to
161+
// each other all come from the same code generation unit, so their
162+
// `partial_cmp` function pointers will never differ.
163+
#[allow(unpredictable_function_pointer_comparisons)]
156164
if self.partial_cmp == other.partial_cmp {
157-
// SAFETY: Both constants have the same comparison function, so they
158-
// must be the same type.
159165
if let Some(ordering) = unsafe { (self.partial_cmp)(self.value, other.value) } {
160166
if !ordering.is_eq() {
161167
return ordering;

0 commit comments

Comments
 (0)