-
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
implement disallowed trait methods #12194
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Alexendoo (or someone else) soon. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
a68178c
to
a9c80e9
Compare
continue; | ||
}; | ||
let self_segs: Vec<_> = self_ty.split("::").collect(); | ||
let self_ress: Vec<_> = clippy_utils::def_path_res(cx, &self_segs); |
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.
Unfortunately, this does not support things like <[T] as U>::u_method
, <&T as U>::u_method
etc due to how the lookup in def_path_res
works
let self_res: Res<rustc_hir::HirId> = match self_ty.kind() { | ||
TyKind::Bool | TyKind::Char | TyKind::Int(_) | TyKind::Uint(_) | TyKind::Float(_) => { | ||
Res::PrimTy(PrimTy::from_name(self_ty.primitive_symbol().unwrap()).unwrap()) | ||
}, | ||
TyKind::Str => Res::PrimTy(PrimTy::Str), | ||
TyKind::Adt(adt, _) => Res::Def( | ||
match adt.adt_kind() { | ||
AdtKind::Struct => rustc_hir::def::DefKind::Struct, | ||
AdtKind::Union => rustc_hir::def::DefKind::Union, | ||
AdtKind::Enum => rustc_hir::def::DefKind::Enum, | ||
}, | ||
adt.did(), | ||
), | ||
// FIXME: these other kinds are not currently supported by disallowed_methods due to how | ||
// def_path_ref is implemented | ||
_ => 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.
I hope there is a better way to do this.
a9c80e9
to
fd7ec8c
Compare
fd7ec8c
to
c2b94ec
Compare
I want to support |
What are your thoughts on this @flip1995? IIRC we didn't want to extend the capabilities of our path parsing too much |
I already dislike the parsing code like it is implemented in this PR. I.e. the split on IIUC the goal here is to specify that a certain trait method should not be allowed on a certain type? Why not invent our own config syntax for this. You could also configure this as
meaning: On the type
Or go crazy with the disallowed_methods = [{ type = "std::string::String", method = "std::default::Default::default" }, "my_crate::my_method" ] But I wouldn't go crazy with the path parsing, as we can't cover everything without completely copying |
☔ The latest upstream changes (presumably #12198) made this pull request unmergeable. Please resolve the merge conflicts. |
Hey @Emilgardis, this is a ping from triage, since there hasn't been any activity in some time. Are you still planning to continue this implementation? If you have any questions, you're always welcome to ask them in this PR or on Zulip. @rustbot author |
Yes, I'm going to continue this eventually! |
Hey this is triage, I'm closing this due to inactivity. If you want to continue this implementation, you're welcome to create a new PR. Thank you for the time, you already put into this! Interested parties are welcome to pick this implementation up as well :) @rustbot label +S-inactive-closed -S-waiting-on-author -S-waiting-on-review |
resolves #8581
changelog: [
disallowed_methods
]: Allow specific trait impls via qualified call syntax to be linted.