Conversation

usamoi

followup of rust-lang/rust#141874

changelog: check f16 and f128 in float_equality_without_abs

@rustbot

r? @llogiq

rustbot has assigned @llogiq.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbotrustbot added the S-waiting-on-reviewStatus: Awaiting review from the assignee but also interested partieslabel Jun 14, 2025
&& let ExprKind::Path(ref epsilon_path) = rhs.kind
&& let Res::Def(DefKind::AssocConst, def_id) = cx.qpath_res(epsilon_path, rhs.hir_id)
&& ([sym::f32_epsilon, sym::f64_epsilon].into_iter().any(|sym| cx.tcx.is_diagnostic_item(sym, def_id)))
&& (sym_epsilon.into_iter().any(|sym| cx.tcx.is_diagnostic_item(sym, def_id)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: you can use get_diagnostic_item to avoid a bunch of query overhead, something like

Suggested change
&& (sym_epsilon.into_iter().any(|sym| cx.tcx.is_diagnostic_item(sym, def_id)))
&& matches!(cx.tcx.get_diagnostic_name(def_id), Some(sym::f16_epsilon | sym::f32_epsilon | sym::f64_epsilon | sym::f128_epsilon))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's too long so rustfmt complains error[internal]: line formatted, but exceeded maximum width.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can split the line by hand and make rustfmt happy.

@y21

Can you also add tests for this? It seems like there's also a f16_f128 FIXME in the code that could easily be resolved in the same PR here:

// FIXME(f16_f128): add tests for these types when abs is available

@usamoi

Can you also add tests for this?

Added.

Sign up for free to join this conversation on . Already have an account? Sign in to comment
S-waiting-on-reviewStatus: Awaiting review from the assignee but also interested parties
None yet

Successfully merging this pull request may close these issues.