Skip to content
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

Merged
merged 3 commits into from
Feb 6, 2022
Merged

Conversation

Jarcho
Copy link
Contributor

@Jarcho Jarcho commented Feb 6, 2022

Partially implements #3999 and #546

This doesn't consider enums 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

@Jarcho Jarcho changed the title Unordered transmute Add lint transmute_undefined_repr Feb 6, 2022
@rust-highfive
Copy link

r? @llogiq

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Feb 6, 2022
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;
Copy link
Contributor

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;
Copy link
Contributor

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.

@llogiq
Copy link
Contributor

llogiq commented Feb 6, 2022

Just one very small nit, otherwise this looks fine. Great work, as always.

@llogiq
Copy link
Contributor

llogiq commented Feb 6, 2022

Thank you! @bors r+

@bors
Copy link
Contributor

bors commented Feb 6, 2022

📌 Commit 68993b1 has been approved by llogiq

@bors
Copy link
Contributor

bors commented Feb 6, 2022

⌛ Testing commit 68993b1 with merge 093e320...

@bors
Copy link
Contributor

bors commented Feb 6, 2022

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: llogiq
Pushing 093e320 to master...

@bors bors merged commit 093e320 into rust-lang:master Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants