Repository: rust-lang/rust
File: compiler/rustc_lint/src/builtin.rs (Rust)

Code before:
    /// pub struct Foo;
    ///
    /// impl Eq for Foo {
    ///     fn assert_receiver_is_total_eq(&self) {}
    /// }
    /// ```
    ///
    /// {{produces}}
    ///
    /// ### Explanation
    ///
    /// This method exists so that `#[derive(Eq)]` can check that all
    /// fields of a type implement `Eq`. Other users were never supposed
    /// to implement it and it was hidden from documentation.
    ///
    /// Unfortunately, it was not explicitly marked as unstable and some
    /// people have now mistakenly assumed they had to implement this method.
    ///
    /// As the method is never called by the standard library, you can safely
    /// remove any implementations of the method and just write `impl Eq for Foo {}`.
    ///
    /// This is a [future-incompatible] lint to transition this to a hard
    /// error in the future. See [issue #150000] for more details.
    ///
    /// [issue #150000]: https://github.com/rust-lang/rust/issues/150000
    pub EQ_ASSERT_RECEIVER_IS_TOTAL_EQ_IMPL,
    Warn,
    "manual implementation of the internal `Eq::assert_receiver_is_total_eq` method",
    @future_incompatible = FutureIncompatibleInfo {
        reason: fcw!(FutureReleaseError #150000),
        report_in_deps: false,
    };
}

declare_lint_pass!(EqAssertReceiverIsTotalEq => [EQ_ASSERT_RECEIVER_IS_TOTAL_EQ_IMPL]);

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,
            );
        }
    }

Review comment (suggestion):
Per our RFC 0344 guidance, at a minimum we need to rename this lint into the plural.

The name would still be kind of rough though.  Unless someone knows that method exists, the lint name would read rather oddly (especially due to the "is" in the name).

Maybe `internal_eq_trait_method_impls` would be better.


Code after:
    /// {{produces}}
    ///
    /// ### Explanation
    ///
    /// This method existed so that `#[derive(Eq)]` could check that all
    /// fields of a type implement `Eq`. Other users were never supposed
    /// to implement it and it was hidden from documentation.
    ///
    /// Unfortunately, it was not explicitly marked as unstable and some
    /// people have now mistakenly assumed they had to implement this method.
    ///
    /// As the method is never called by the standard library, you can safely
    /// remove any implementations of the method and just write `impl Eq for Foo {}`.
    ///
    /// This is a [future-incompatible] lint to transition this to a hard
    /// error in the future. See [issue #152336] for more details.
    ///
    /// [issue #152336]: https://github.com/rust-lang/rust/issues/152336
    pub INTERNAL_EQ_TRAIT_METHOD_IMPLS,
    Warn,
    "manual implementation of the internal `Eq::assert_receiver_is_total_eq` method",
    @future_incompatible = FutureIncompatibleInfo {
        reason: fcw!(FutureReleaseError #152336),
        report_in_deps: false,
    };
}

declare_lint_pass!(InternalEqTraitMethodImpls => [INTERNAL_EQ_TRAIT_METHOD_IMPLS]);

impl<'tcx> LateLintPass<'tcx> for InternalEqTraitMethodImpls {
    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
            && cx.tcx.is_diagnostic_item(sym::assert_receiver_is_total_eq, trait_item_def_id)
        {
            cx.emit_span_lint(
                INTERNAL_EQ_TRAIT_METHOD_IMPLS,
                item.span,
                EqInternalMethodImplemented,
            );
        }
    }
}