Skip to content

don't generate extra impl for Eq assertions #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fee1-dead
Copy link

Eq already has a method assert_receiver_is_total_eq that allows you to put asserts in. This PR makes it so we use that instead of generating a new trait and impl every time (which could be a lot).

This is also a cleanup because apparently additional_impl is only used by Eq (and arguably quite confusing as additional_impl is used to generate the Eq impl while the "main" impl was the extra impl) so we can remove that now.

generating a struct __AssertEq each time is still a little wasteful, but given that derive-where is a single crate (so no "normal" support crate to share types) it might be unavoidable.

Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 10, 2025
…r, r=jieyouxu

some `derive_more` refactors

some clauses can be merged together without requiring an attribute for each trait derived.

also manually impl `Eq` because the `derive_where` generated code is too much for my comfort (cc ModProg/derive-where#128)
Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 10, 2025
…r, r=jieyouxu

some `derive_more` refactors

some clauses can be merged together without requiring an attribute for each trait derived.

also manually impl `Eq` because the `derive_where` generated code is too much for my comfort (cc ModProg/derive-where#128)
Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 10, 2025
…r, r=jieyouxu

some `derive_more` refactors

some clauses can be merged together without requiring an attribute for each trait derived.

also manually impl `Eq` because the `derive_where` generated code is too much for my comfort (cc ModProg/derive-where#128)
Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 10, 2025
…r, r=jieyouxu

some `derive_more` refactors

some clauses can be merged together without requiring an attribute for each trait derived.

also manually impl `Eq` because the `derive_where` generated code is too much for my comfort (cc ModProg/derive-where#128)
Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 10, 2025
…r, r=jieyouxu

some `derive_more` refactors

some clauses can be merged together without requiring an attribute for each trait derived.

also manually impl `Eq` because the `derive_where` generated code is too much for my comfort (cc ModProg/derive-where#128)
rust-timer added a commit to rust-lang/rust that referenced this pull request Aug 10, 2025
Rollup merge of #145145 - fee1-dead-contrib:push-qnmpmtmtpkkr, r=jieyouxu

some `derive_more` refactors

some clauses can be merged together without requiring an attribute for each trait derived.

also manually impl `Eq` because the `derive_where` generated code is too much for my comfort (cc ModProg/derive-where#128)
Copy link
Collaborator

@daxpedda daxpedda left a comment

Choose a reason for hiding this comment

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

I specifically removed this a while ago because assert_receiver_is_total_eq() is and undocumented method and therefor unstable.

But I agree that the current state is not ideal and we actually considered splitting the crate into a normal and proc-macro crate for this reason specifically.

@fee1-dead
Copy link
Author

incorrect. the method is marked as #[stable] since Rust 1.0. It's not going to be removed just because it is doc(hidden). If the libs team wanted to leave it open for removal they would have used the unstable attribute.

@daxpedda
Copy link
Collaborator

daxpedda commented Aug 12, 2025

All methods in Std marked with #[doc(hidden)] are API unstable. #[stable] just means its available on Rust stable, it doesn't mean it is API stable. E.g. I remember there being a #[doc(hidden)] function to define where the output of println! goes that was simply removed. It was used extensively with Wasm.

EDIT: the function was called set_print().

I'm happy to be told otherwise if you can find me something concrete on that topic, I myself don't have anything concrete on it.

@fee1-dead
Copy link
Author

EDIT: the function was called set_print().

This was removed in this PR: rust-lang/rust@aff7bd6 (#78714). Note that what defined whether something was stable or not was through the #[stable] and #[unstable] attribute. set_print had an #[unstable] attribute, i.e. you had to be on nightly and use feature() to use it:

#[unstable(feature = "libstd_io_internals", issue = "42788")]
#[doc(no_inline, hidden)]
pub use self::stdio::{set_panic, set_print};

The method we're using in this PR is stable:

    #[stable(feature = "rust1", since = "1.0.0")]
    fn assert_receiver_is_total_eq(&self) {}

This is stable Rust so there's no way the libs team can remove it as it would be a breaking change.

@fee1-dead
Copy link
Author

So

#[stable] just means its available on Rust stable, it doesn't mean it is API stable.

is not true. Rust stdlib maintainers cannot make breaking changes to stable code. That's outlined in https://rust-lang.github.io/rfcs/1105-api-evolution.html - #[stable] absolutely constitutes stable code.

@daxpedda
Copy link
Collaborator

set_print had an #[unstable] attribute, i.e. you had to be on nightly and use feature() to use it:

Ah, good catch.

So

#[stable] just means its available on Rust stable, it doesn't mean it is API stable.

is not true. Rust stdlib maintainers cannot make breaking changes to stable code. That's outlined in https://rust-lang.github.io/rfcs/1105-api-evolution.html - #[stable] absolutely constitutes stable code.

I'm not seeing that #[stable] constitutes stable API in RFC 1105. Can you quote the relevant paragraph?

@daxpedda
Copy link
Collaborator

daxpedda commented Aug 12, 2025

Worst case scenario: I'm happy to take a quote from a Rust team member on e.g. Zulip or something.

@fee1-dead
Copy link
Author

fee1-dead commented Aug 12, 2025

See also https://rustc-dev-guide.rust-lang.org/stability.html.

I'm a Rust team member, although I primary work with the compiler (I'm a compiler maintainer). I am confident that #[stable] means assert_receiver_is_total_eq will never get removed. idk if you want me to go on Zulip and ask libs specifically, don't think that is necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants