Skip to content

Conversation

@cyrgani
Copy link
Contributor

@cyrgani cyrgani commented Dec 14, 2025

The Eq::assert_receiver_is_total_eq method is purely meant as an implementation detail by #[derive(Eq)] to add checks that all fields of the type the derive is applied to also implement Eq.
The method is already #[doc(hidden)] and has a comment saying // This should never be implemented by hand..
Unfortunately, it has been stable since 1.0 and there are some cases on GitHub (https://github.com/search?q=assert_receiver_is_total_eq&type=code) where people have implemented this method manually, sometimes even with actual code in the method body (example: https://github.com/Shresht7/codecrafters-redis-rust/blob/31f0ec453c504b4ab053a7b1c3ff548ff36a9db5/src/parser/resp/types.rs#L255).
To prevent further confusion from this, this PR is deprecating the method and adds a FCW when it is manually implemented (this is necessary as the deprecation warning is not emitted when the method is implemented, only when it is called).
This is similar to what was previously done with the soft_unstable lint (#64266).

See also rust-lang/libs-team#704.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 14, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 14, 2025

r? @madsmtm

rustbot has assigned @madsmtm.
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

Warn,
"manual implementation of the internal `Eq::assert_receiver_is_total_eq` method",
@future_incompatible = FutureIncompatibleInfo {
reason: fcw!(FutureReleaseError #150000),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: create a real tracking issue once there is consensus on this change

@rust-log-analyzer

This comment has been minimized.

@rust-cloud-vms rust-cloud-vms bot force-pushed the no-eq-assert-receiver-method branch from faf29de to 81dc07d Compare December 14, 2025 11:30
@madsmtm madsmtm changed the title deprecate Eq::assert_receiver_is_total_eq and emit a FCW on manual … deprecate Eq::assert_receiver_is_total_eq and emit FCW on manual impls Dec 14, 2025
Copy link
Contributor

@madsmtm madsmtm left a comment

Choose a reason for hiding this comment

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

Implementation looks good, feel free to r=me on that once you have t-libs signoff (FCP?).

Procedurally, this might also need t-lang approval for the lint name IIUC? Or can t-libs decide that?

View changes since this review

@madsmtm madsmtm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 14, 2025
@cyrgani cyrgani added I-lang-nominated Nominated for discussion during a lang team meeting. I-libs-nominated Nominated for discussion during a libs team meeting. labels Dec 14, 2025
@traviscross traviscross added I-libs-api-nominated Nominated for discussion during a libs-api team meeting. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang and removed I-libs-nominated Nominated for discussion during a libs team meeting. labels Dec 17, 2025
@Amanieu
Copy link
Member

Amanieu commented Jan 6, 2026

Since there's never a valid reason to manually implement this method, having an FCW urging people to remove their manual implementation seems like the best way to go.

@rfcbot merge libs-api lang

@rust-rfcbot
Copy link
Collaborator

Error encounted:
Provided team libs-api lang is invalid

@Amanieu Amanieu added T-lang Relevant to the language team T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 6, 2026
@Amanieu
Copy link
Member

Amanieu commented Jan 6, 2026

@rfcbot merge

@rust-rfcbot
Copy link
Collaborator

Error encounted:
Provided team `` is invalid

@Amanieu
Copy link
Member

Amanieu commented Jan 6, 2026

@rfcbot merge libs-api,lang

@rust-rfcbot
Copy link
Collaborator

rust-rfcbot commented Jan 6, 2026

Team member @Amanieu has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Jan 6, 2026
@Amanieu Amanieu removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Jan 6, 2026
@dtolnay
Copy link
Member

dtolnay commented Jan 6, 2026

Since there's never a valid reason to manually implement this method, having an FCW urging people to remove their manual implementation seems like the best way to go.

I don't agree with this. The reason is the same reason that the standard library's derived Eq implementations implement this method. If someone has their own Eq derive macro (e.g. the derive_more use case) they would want to do the same thing.

I am open to deprecating the method, but I would not want to do so while derive(Eq) is continuing to use it. We should first change derive(Eq) to use some other approach. Then, when we deprecate, custom Eq derive macros can mirror the standard library's approach.

@dtolnay
Copy link
Member

dtolnay commented Jan 6, 2026

Ah, relevant line:

&& !item.span.from_expansion()

"Manual" means not from a macro expansion. Then this seems fine.

In the longer term, I would prefer to fully deprecate assert_receiver_is_total_eq including for macro expansions.

@Amanieu
Copy link
Member

Amanieu commented Jan 7, 2026

assert_receiver_is_total_eq only exists because the derive needs a body in which to put static assertions (that the struct members all implement Eq). Back in 1.0, this was the only that this could be done. Today, you could do this by having the derive emit something like:

const _: () = {
    fn assert_receiver_is_total_eq<Generics>() {
        ..
    }
};

So even custom derives of Eq do not need this method any more.

Comment on lines 3238 to 3253
impl<'tcx> LateLintPass<'tcx> for EqAssertReceiverIsTotalEq {
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx rustc_hir::ImplItem<'tcx>) {
if let ImplItemImplKind::Trait { defaultness: _, trait_item_def_id: Ok(trait_item_def_id) } =
item.impl_kind
&& item.ident.name == sym::assert_receiver_is_total_eq
&& cx.tcx.is_diagnostic_item(sym::assert_receiver_is_total_eq, trait_item_def_id)
&& !item.span.from_expansion()
{
cx.emit_span_lint(
EQ_ASSERT_RECEIVER_IS_TOTAL_EQ_IMPL,
item.span,
EqInternalMethodImplemented,
);
}
}
}
Copy link
Contributor

@traviscross traviscross Jan 8, 2026

Choose a reason for hiding this comment

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

I gather this !item.span.from_expansion() check suppresses the lint for impls from all macro expansions, i.e. even for user-defined macros. Given that we want to catch as much as possible so as to be able to make this into an error, perhaps a more strict check is in order?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the lint to fire in every case and added an explicit #[allow(internal_eq_trait_method_impls)] to the method generated by derive(Eq).

@rustbot
Copy link
Collaborator

rustbot commented Jan 8, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rust-cloud-vms rust-cloud-vms bot force-pushed the no-eq-assert-receiver-method branch from 81dc07d to 62743e8 Compare January 8, 2026 12:18
@rustbot
Copy link
Collaborator

rustbot commented Jan 8, 2026

Changes to the code generated for builtin derived traits.

cc @nnethercote

@rustbot
Copy link
Collaborator

rustbot commented Jan 8, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer

This comment has been minimized.

@rust-cloud-vms rust-cloud-vms bot force-pushed the no-eq-assert-receiver-method branch from 62743e8 to 4ee1588 Compare January 8, 2026 14:36
Copy link
Contributor

@traviscross traviscross left a comment

Choose a reason for hiding this comment

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

Looks good to me modulo the marked TODOs.

@rfcbot reviewed

View changes since this review

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 13, 2026

☔ The latest upstream changes (presumably #151051) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. I-lang-nominated Nominated for discussion during a lang team meeting. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-lang Relevant to the language team T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants