-
Notifications
You must be signed in to change notification settings - Fork 1.8k
clippy_utils
: make peel_*_ty_refs
class of functions a bit more consistent
#15515
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
r? @Alexendoo rustbot has assigned @Alexendoo. Use |
This comment has been minimized.
This comment has been minimized.
Right. I don't really understand why rustfmt is complaining about the line -- it's even marked with EDIT: ah, it's not quite that: what rustfmt actually tries to format is the import line (because of the moved |
Also it's a shame that |
5e9ebc1
to
be3f4a8
Compare
Why? If I remember correctly, the results from |
Oh is it? That's nice. I guess the other direction ( |
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 like clean ups in general, as they reduce the technical debt.
However, when you use longer commit messages, could you use proper sentences and casing in them? It's ok for the short message to be concise, even though most of us still use proper casing, but longer messages should be both useful and easy to read.
} | ||
/// Peels off all references on the type. Returns the underlying type and the number of references | ||
/// removed. | ||
pub fn peel_middle_ty_refs(mut ty: Ty<'_>) -> (Ty<'_>, usize) { |
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 peel_and_count_refs
would be a better name, we are in the ty
module so I don't think it is useful to repeat "middle" 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.
I would agree if this were a method on middle::Ty
, but it's a freestanding function which is often imported unqualified, so having some redundancy in the name could be helpful imo, WDYT?
The and_count
part I do agree with though.
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 is the only part in Clippy where we use "middle_ty" as part of a function name, this is why it looks odd to me. And this is never used in the whole compiler as part of a function name either. In case of an ambiguity, it looks like "hir_ty" is used for rustc_hir::Ty
, while "ty" is used for rustc_middle::ty::Ty
.
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.
Fair enough. There's also peel_mid_ty_refs_is_mutable
right beside it, and I'd like to give it a similarly structured name, but that's a bit hard given that that function does many things at once.
Maybe something like peel_ty_refs_with_count
and peel_ty_refs_with_count_is_mutable
?
r? samueltardieu @rustbot author |
Reminder, once the PR becomes ready for a review, use |
This comment has been minimized.
This comment has been minimized.
more concise
we're peeling here
they are literally the same function
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. |
I was looking for the function that peels refs from a type while also returning the number of refs peeled, and it turns out there were actually two of them?? I removed the by far less popular one, and made some other clean-up along the way
changelog: none