-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Labels
A-lintArea: New lintsArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.L-guidelinesLint: Related to the Rust API GuidelinesLint: Related to the Rust API GuidelinesL-unnecessaryLint: Warn about unnecessary codeLint: Warn about unnecessary codeT-middleType: Probably requires verifiying typesType: Probably requires verifiying types
Description
This code
pub unsafe fn bad(a: [u32; 4], idx: usize) -> u64 {
union A { _a: [u32; 4], b: [u64; 2] };
::std::mem::transmute::<[u32; 4], A>(a).b[idx]
}should be more idiomatically be written as this:
pub unsafe fn better(a: [u32; 4], idx: usize) -> u64 {
union A { a: [u32; 4], b: [u64; 2] };
A { a: a }.b[idx] // the a: a has been added for clarity, a suffices
}Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.Call for participation: Medium difficulty level problem and requires some initial experience.L-guidelinesLint: Related to the Rust API GuidelinesLint: Related to the Rust API GuidelinesL-unnecessaryLint: Warn about unnecessary codeLint: Warn about unnecessary codeT-middleType: Probably requires verifiying typesType: Probably requires verifiying types