-
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 lint transmute_undefined_repr
#8398
Conversation
r? @llogiq (rust-highfive has picked a reviewer for you, use r? to override) |
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) { | ||
if_chain! { | ||
if let ExprKind::Call(path_expr, args) = e.kind; | ||
if let ExprKind::Call(path_expr, [arg]) = e.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.
👍
@@ -26,7 +26,7 @@ pub(super) fn check<'tcx>( | |||
e.span, | |||
&format!("transmute from a `{}` to a `{}`", from_ty, to_ty), | |||
|diag| { | |||
let mut expr = &args[0]; | |||
let mut expr = arg; |
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 could take mut arg
and inline this.
Just one very small nit, otherwise this looks fine. Great work, as always. |
Thank you! @bors r+ |
📌 Commit 68993b1 has been approved by |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Partially implements #3999 and #546
This doesn't consider
enum
s at all right now as those are going to be a pain to deal with. This also allows#[repr(Rust)]
structs with only one non-zero sized fields. I think those are technically undefined when transmuted.changelog: Add lint
transmute_undefined_repr