-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix: add fallback case in generated PartialEq
impl
#13732
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b44f07a
to
fed74c8
Compare
lowr
reviewed
Dec 6, 2022
crates/ide-assists/src/handlers/replace_derive_with_manual_impl.rs
Outdated
Show resolved
Hide resolved
LGTM :) Maintainers that have write permissions should review in a few days. |
@bors r+ |
☀️ Test successful - checks-actions |
changelog fix (first contribution) add fallback case to generated |
bors
added a commit
that referenced
this pull request
Jan 9, 2023
fix: add generic `TypeBoundList` in generated derivable impl Potentially fixes #13727. Continuing with the work in #13732, this fix tries to add correct type bounds in the generated `impl` block: ```diff enum Either<T, U> { Left(T), Right(U), } - impl<T, U> PartialEq for Either<T, U> { + impl<T: PartialEq, U: PartialEq> PartialEq for Either<T, U> { fn eq(&self, other: &Self) -> bool { match (self, other) { (Self::Left(l0), Self::Left(r0)) => l0 == r0, (Self::Right(l0), Self::Right(r0)) => l0 == r0, _ => false, } } } ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Partially fixes #13727.
When generating
PartialEq
implementations for enums, the original code can already generate the following fallback case:However, it has been suppressed in the following example for no good reason:
This PR has removed that suppression logic.
Of course, the PR could have suppressed the fallback case generation for single-variant enums instead, but I believe that this case is quite rare and should be caught by#[warn(unreachable_patterns)]
anyway.After this fix, when the enum has >1 variants, the following fallback arm will be generated :
_ => false,
if we've already gone through every case where the variants ofself
andother
match;Note: The code example is still wrong after the fix due to incorrect trait bounds.