-
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
Add size_of_ref lint #10098
Add size_of_ref lint #10098
Conversation
r? @Jarcho (rustbot has picked a reviewer for you, use r? to override) |
☔ The latest upstream changes (presumably #10099) made this pull request unmergeable. Please resolve the merge conflicts. |
9a8fba7
to
4826743
Compare
☔ The latest upstream changes (presumably #10063) made this pull request unmergeable. Please resolve the merge conflicts. |
4826743
to
8b36c80
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.
This would be better as suspicious
. It's an easy mistake to make, but it's not inherently wrong and the alternative requires writing out the type name which could be a long.
Ah sorry, I was lazy :-/ Will squash if needed |
4cacc4f
to
eac3349
Compare
It's better if it's squashed, but not a big deal. |
eac3349
to
d7b9e19
Compare
squashed |
Thank you. @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
This addresses #9995, which is likely raising a valid point about
std::mem::size_of_val()
: It's very easy to use double-references as the argument, which the function will happily accept and give back the size of the reference, not the size of the value behind the reference. In the worst case, if the value matches the programmer's expectation, this seems to work, while in fact, everything will go horribly wrong e.g. on a different platform.The size of a
&T
is independent of whatT
is, and people might want to usestd::mem::size_of_val()
to actually get the size of any reference (e.g. via&&()
). I would rather suggest that this is always bad behavior, though (instead, and). I, therefore, put this lint intocorrectness
.Since the problem is usually easily fixed by removing extra
&
, I went light on suggesting code.changelog: New lint: [
size_of_ref
]#10098