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

New lint: transmute-num-to-bytes #7803

Closed
aDotInTheVoid opened this issue Oct 11, 2021 · 1 comment · Fixed by #7805
Closed

New lint: transmute-num-to-bytes #7803

aDotInTheVoid opened this issue Oct 11, 2021 · 1 comment · Fixed by #7805
Assignees
Labels
A-lint Area: New lints

Comments

@aDotInTheVoid
Copy link
Member

aDotInTheVoid commented Oct 11, 2021

What it does

Detect open coding of (primitive int/float).to_ne_bytes() with transmute

Categories (optional)

  • Kind: complexity

What is the advantage of the recommended code over the original code

Clearer, Removes unsafe

Drawbacks

None.

Example

let x: [u8; 8] = std::mem::transmute(0.0_f64)

Could be written as:

let x: [u8; 8] = 0.0_f64.to_ne_bytes()
@aDotInTheVoid aDotInTheVoid added the A-lint Area: New lints label Oct 11, 2021
@aDotInTheVoid
Copy link
Member Author

@rustbot claim

aDotInTheVoid added a commit to aDotInTheVoid/rust-clippy that referenced this issue Oct 11, 2021
Closes rust-lang#7803

changelog: [`transmute_num_to_bytes`] new lint
aDotInTheVoid added a commit to aDotInTheVoid/rust-clippy that referenced this issue Oct 11, 2021
Closes rust-lang#7803

changelog: [`transmute_num_to_bytes`] new lint
bors added a commit that referenced this issue Oct 13, 2021
Add lint transmute_num_to_bytes

Closes #7803

changelog: [`transmute_num_to_bytes`] new lint
aDotInTheVoid added a commit to aDotInTheVoid/rust-clippy that referenced this issue Oct 13, 2021
Closes rust-lang#7803

changelog: [`transmute_num_to_bytes`] new lint
bors added a commit that referenced this issue Oct 13, 2021
Add lint transmute_num_to_bytes

Closes #7803

changelog: [`transmute_num_to_bytes`] new lint
@bors bors closed this as completed in 5896980 Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant