-
Notifications
You must be signed in to change notification settings - Fork 1.8k
refactor(non_canonical_impls): lint starting from impl
s
#15749
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: master
Are you sure you want to change the base?
Conversation
No changes for 3c02c0e |
7b7a795
to
9718c47
Compare
The PR was merged, so @rustbot label -S-blocked |
9718c47
to
948e23d
Compare
This comment has been minimized.
This comment has been minimized.
948e23d
to
2168603
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.
Not a change you made, but can you move the trait impl type argument check for PartialOrd
to be before walking the assoc items. If the left and right types don't match then there is no Ord
impl to call.
Good idea. I'd like to keep that a separate commit though, if that's okay |
2168603
to
e776e42
Compare
This comment has been minimized.
This comment has been minimized.
// If `Self` and `Rhs` are not the same type, then a corresponding `Ord` impl is not possible, | ||
// since it doesn't have an `Rhs` | ||
&& match trait_impl.args.as_slice() { | ||
[_] => true, |
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.
If this happens something is very broken. All argument lists are complete once you get to the type system layer in the compiler so both arguments to PartialOrd
(Self
and Rhs
) have to exist here.
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.
Ah, I thought there will be only one argument if Self
=Rhs
&& let Some(of_trait) = impl_.of_trait | ||
&& let Some(trait_did) = of_trait.trait_ref.trait_def_id() | ||
// Check this early to hopefully bail out as soon as possible | ||
&& [self.clone_trait, self.partial_ord_trait].contains(&Some(trait_did)) |
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 should just convert it to an enum and do an exhaustive match later.
for (assoc, body, block) in assoc_fns { | ||
if assoc.ident.name == sym::partial_cmp { | ||
check_partial_ord_on_ord(cx, assoc, item, body, block); | ||
} | ||
} |
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.
You can use assoc_fns.iter().find(..)
since there should only be one function with that name.
if is_from_proc_macro(cx, impl_item) { | ||
return; | ||
} |
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.
nit: Why the nested if instead of && !is_from_proc_macro(..)
.
This comment has been minimized.
This comment has been minimized.
The missing external macro test for `non_canonical_clone_impl` was caught thanks to lintcheck -- I went ahead and added all the other combinations of the test while at it
e776e42
to
3c02c0e
Compare
This PR was rebased onto a different master 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. |
@rustbot ready |
Based on #15520 (comment), with the following changes/additions:
Trait
enum for quickly filtering out irrelevant impls -- instead, check thetrait_of
basically right away:DefId
s of the relevant traits into the lint passcx.tcx.impl_trait_ref
's output for the theDefId
of the trait being implementedDefId
s, which should be very cheapself_ty
implements the other relevant trait.changelog: none
Not auto-assigning since @blyxyas and/or @Jarcho will be the ones reviewing it:
r? ghost