-
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 e776e42 |
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.
&& let Node::Item(item) = cx.tcx.parent_hir_node(impl_item.hir_id()) | ||
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { | ||
if let ItemKind::Impl(impl_) = item.kind | ||
&& (1..=2).contains(&impl_.items.len()) |
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 needs at least since PartialOrd
can have five function.
You'll also want to figure if the trait is one we need to check here before doing anything else. Get the DefId
from the path to avoid doing a query.
.iter() | ||
.map(|id| cx.tcx.hir_impl_item(*id)) | ||
.filter_map(|assoc| { | ||
if let ImplItemKind::Fn(_, assoc_id) = assoc.kind |
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: body_id
not assoc_id
.
for (assoc, _, block) in assoc_fns { | ||
// NOTE: we don't bother doing the method name check before the proc-macro check, because we | ||
// lint both methods of `Clone`, and therefore would need to repeat the proc-macro check anyway | ||
if !is_from_proc_macro(cx, assoc) { |
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.
is_from_proc_macro
should be moved right before emitting the lint. It's very unlikely to actually filter anything.
for (assoc, body, block) in assoc_fns { | ||
// NOTE: `PartialOrd` has methods `lt/le/ge/gt` which we don't lint, so | ||
// don't bother checking whether _they_ come from a proc-macro | ||
if assoc.ident.name == sym::partial_cmp && !is_from_proc_macro(cx, assoc) { |
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.
is_from_proc_macro
should be moved right before emitting the lint. It's very unlikely to actually filter anything.
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
Good idea. I'd like to keep that a separate commit though, if that's okay |
2168603
to
e776e42
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. |
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