-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
New lint [manual_partial_ord_and_ord_impl
]
#10788
New lint [manual_partial_ord_and_ord_impl
]
#10788
Conversation
r? @llogiq (rustbot has picked a reviewer for you, use r? to override) |
☔ The latest upstream changes (presumably #10810) made this pull request unmergeable. Please resolve the merge conflicts. |
f3b63ba
to
cbd63a5
Compare
Yep, will also review it! |
I feel like |
"change this to", | ||
format!("{{ Some(self.cmp({})) }}", param_ident.name), | ||
// TODO: This is always correct afaik. | ||
Applicability::MaybeIncorrect |
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 would probably use Applicability::Unspecified
until we have some tool (likely a new implementation to lintcheck
) to measure breaking changes when suggestions change in a bigger scope (instead of the 26 current crates, a bigger dataset).
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.
What happens if the PartialOrd
implementation has side effects? 🤔
In that case, PartialOrd
cannot be replaced with Some(self.cmp(other))
(this is a very edgy edge-case)
impl Ord for A {
fn cmp(&self, other: &Self) -> Ordering {
todo!();
}
}
impl PartialOrd for A {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
fn_with_side_effects();
todo!();
}
}
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.
That would break it, yes. Though I'm not sure if this is too big of an issue since implementations of PartialOrd
and Ord
must agree; I'm not sure if this extends to printing to stdout or mutating a static and whatnot but generally, this would be a pretty terrible idea anyway.
There's also derive_ord_xor_partial_ord
, which is similar and disallows the implementation even if it has side effects afaict.
Sorry for taking so long to review, it looks like a very useful lint, even tho not a lot of people manually implement |
e4ac6ba
to
c10fc0f
Compare
lintcheck reveals 4 instances of |
1deaa44
to
7f43e0f
Compare
Could you split these two lints into two different PRs so they're easier to review and easier for generating the changelog? (and a simpler Git structure in general) |
0a7ec70
to
cfcf04b
Compare
From the newly created PRs, it looks like the lints were quite different. So asking this is reasonable. For further reference, you can just add multiple changelog: new lint XYZ works just fine. Also, a small warning, that at one point you might encounter contributors, who are not as proficient with git as you are. And in this regard, just to add even more to this totally side tracked comment: I can recommend playing a bit with aliases for git if you use the console. I have a few for fast rebasing of just fixing up the last commit. :) |
☔ The latest upstream changes (presumably #10921) made this pull request unmergeable. Please resolve the merge conflicts. |
2f48612
to
f3875c7
Compare
☔ The latest upstream changes (presumably #10827) made this pull request unmergeable. Please resolve the merge conflicts. |
40227bb
to
1af0124
Compare
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.
Some small changes and I think it's pretty ready to be merged 👍 (The other
or self
comment has to be addressed tho, I actually think it's a bug)
☔ The latest upstream changes (presumably #10934) made this pull request unmergeable. Please resolve the merge conflicts. |
c5c1a77
to
c515a30
Compare
c515a30
to
f2cccc2
Compare
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 think this is complete. Thanks! ❤️
cc @xFrednet
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.
Looks good overall, I have a few minor comments, and then it should be ready for bors consumption :D
impl PartialOrd for B { | ||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> { | ||
Some(self.cmp(other)) | ||
} | ||
} |
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've just checked and self.cmp(other).into()
also wraps the result into Some
. If it's simple to implement, can you also check for this kind of body and accept it as a correct implementation?
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 feel like handling all cases like that is a bit challenging, you could also do Some(Self::cmp(self, other))
I'm pretty sure which should be correct but isn't caught
2a3354f
to
8f302dc
Compare
regex test failed, see #11111 |
8f302dc
to
862f82b
Compare
☔ The latest upstream changes (presumably #11122) made this pull request unmergeable. Please resolve the merge conflicts. |
This version looks good to me. Could you rebase on master and also squash the changes into 1-4 commits? Then everything should be ready. Here you can also Thank you for the update and review you two! Bors, you know what to do :D |
first try at this
cargo dev fmt cargo test passes cargo test passes refactor a lil Update bool_comparison.stderr heavily refactor + bump `clippy::version` refactor refactor check bounds to increase accuracy, and add todos
862f82b
to
a5dfb68
Compare
@bors r=xFrednet,blyxyas |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Lints when both
PartialOrd
andOrd
are manually implemented yet the body ofPartialOrd::partial_cmp
isn'tSome(self.cmp(<other>))
.This is in
correctness
currently but I'm ok with elsewhere.Closes #10744
changelog: new lint [
needless_partial_ord_impl
]#10788