Skip to content

Commit 4d49693

Browse files
committed
auto merge of #13643 : aochagavia/rust/pr-2, r=alexcrichton
Fixed a typo in the documentation of std::mem, and refactored a function to use match instead of if. Also added a FIXME to the benchmarks at the end of the file stating that they should be moved to another place, because they have nothing to do with `mem` (see #13642)
2 parents a27dc53 + e36adee commit 4d49693

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/libstd/mem.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ pub fn size_of_val<T>(_val: &T) -> uint {
3737
/// Useful for building structures containing variable-length arrays.
3838
#[inline]
3939
pub fn nonzero_size_of<T>() -> uint {
40-
let s = size_of::<T>();
41-
if s == 0 { 1 } else { s }
40+
match size_of::<T>() {
41+
0 => 1,
42+
x => x
43+
}
4244
}
4345

4446
/// Returns the size in bytes of the type of the value that `_val` points to.
@@ -222,7 +224,6 @@ pub unsafe fn move_val_init<T>(dst: &mut T, src: T) {
222224
/// On big endian, this is a no-op. On little endian, the bytes are swapped.
223225
#[cfg(target_endian = "big")] #[inline] pub fn from_be64(x: u64) -> u64 { x }
224226

225-
226227
/**
227228
* Swap the values at two mutable locations of the same type, without
228229
* deinitialising or copying either one.
@@ -238,7 +239,7 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
238239
ptr::copy_nonoverlapping_memory(x, &*y, 1);
239240
ptr::copy_nonoverlapping_memory(y, &t, 1);
240241

241-
// y and t now point to the same thing, but we need to completely forget `tmp`
242+
// y and t now point to the same thing, but we need to completely forget `t`
242243
// because it's no longer relevant.
243244
cast::forget(t);
244245
}
@@ -360,6 +361,7 @@ mod tests {
360361
}
361362
}
362363

364+
// FIXME #13642 (these benchmarks should be in another place)
363365
/// Completely miscellaneous language-construct benchmarks.
364366
#[cfg(test)]
365367
mod bench {

0 commit comments

Comments
 (0)