-
-
Notifications
You must be signed in to change notification settings - Fork 14.5k
deprecate Eq::assert_receiver_is_total_eq and emit FCW on manual impls
#149978
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
base: main
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
faf29de to
81dc07d
Compare
Eq::assert_receiver_is_total_eq and emit a FCW on manual …Eq::assert_receiver_is_total_eq and emit FCW on manual impls
There was a problem hiding this 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?
|
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 |
|
Error encounted: |
|
@rfcbot merge |
|
Error encounted: |
|
@rfcbot merge libs-api,lang |
|
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. |
|
🔔 This is now entering its final comment period, as per the review above. 🔔 |
|
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. |
4ee1588 to
bf5d08f
Compare
This comment has been minimized.
This comment has been minimized.
| cx.attr_nested_word(sym::doc, sym::hidden, span), | ||
| cx.attr_nested_word(sym::coverage, sym::off, span) | ||
| cx.attr_nested_word(sym::coverage, sym::off, span), | ||
| cx.attr_nested_word(sym::allow, sym::internal_eq_trait_method_impls, span) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Does this mean that if I type #![forbid(internal_eq_trait_method_impls)], I can't derive PartialEq and Eq? Or is the span of the macro properly tracked such that lint levels like this isn't an issue? I can't recall the details there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is indeed a problem. The easiest fix I could think of for now was to add a second hidden, unstable method to Eq and move all the assertions into that method. (this is what this PR does now)
I tried to implement the above design with a const _, but encountered a problem with this code:
#[derive(PartialEq, Eq)]
pub struct A<'a, T>(&'a [T]);Cleaning up the derive macro output, the difference is:
pub struct A<'a, T>(&'a [T]);
impl<'a, T> A<'a, T> {
fn old_way() {
let _: &'a [T];
}
}
const _: () = {
fn new_way<'a, T>() {
let _: &'a [T];
}
};and new_way errors with error[E0309]: the parameter type T may not live long enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should've been clearer in my wording here: I don't think actually think it's a blocking concern, people don't do #![forbid] that often, and this is a FCW, and the intention is for it to be unnecessary in the future when we figure out how to do the impl in a const _: ().
I just noticed it and thought it might be worthwhile to discuss the tradeoffs off.
I think I like the previous version of the PR better, adding the extra assert_fields_are_eq feels confusing (as a user, it's already weird to go look at Eq's implementation and see a private method, seeing yet another one doesn't help).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re the error, it is indeed odd that type parameters work that way. But maybe something like this could work?
const _: () = {
struct __AssertIsEq<'a, T: core::eq::Eq>(core::eq::AssertParamIsEq<&'a [T]>);
};There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(In any case, I'd prefer that actually fixing the derive macro is done in a different PR).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the old approach, I'm worried that someone might have #![forbid(future_incompatible)] in their code and would now get a confusing error from inside #[derive(Eq)]. (138 uses with github search)
Also I opened #152504 for the migration of the macro away from the function.
bf5d08f to
3a8632c
Compare
…JonathanBrouwer allow `deprecated(since = "CURRENT_RUSTC_VERSION")` Motivated by rust-lang#149978.
3a8632c to
03140f2
Compare
|
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. |
|
The job Click to see the possible cause of the failure (guessed by this bot) |
The
Eq::assert_receiver_is_total_eqmethod 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 implementEq.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_unstablelint (#64266).See also rust-lang/libs-team#704.