about summary refs log tree commit diff
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2023-03-17 19:29:23 -0700
committerScott McMurray <scottmcm@users.noreply.github.com>2023-03-17 19:55:49 -0700
commit35088797aec481a9549d5d495b27ce9f1e3a39dd (patch)
tree3149b05bf9937c72534e6c884a14e3a36def1be3
parente4b9f86054c581d931f8bad0c87523c53e1e8e3f (diff)
downloadrust-35088797aec481a9549d5d495b27ce9f1e3a39dd.tar.gz
rust-35088797aec481a9549d5d495b27ce9f1e3a39dd.zip
Use `size_of_val` instead of manual calculation
Very minor thing that I happened to notice in passing, but it's both shorter and means it gets `mul nuw`, so why not.
-rw-r--r--compiler/rustc_codegen_ssa/src/glue.rs2
-rw-r--r--library/core/src/hash/mod.rs2
2 files changed, 2 insertions, 2 deletions
diff --git a/compiler/rustc_codegen_ssa/src/glue.rs b/compiler/rustc_codegen_ssa/src/glue.rs
index 0f6e6032f9b..c34f1dbf856 100644
--- a/compiler/rustc_codegen_ssa/src/glue.rs
+++ b/compiler/rustc_codegen_ssa/src/glue.rs
@@ -46,7 +46,7 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
                 // NOTE: ideally, we want the effects of both `unchecked_smul` and `unchecked_umul`
                 // (resulting in `mul nsw nuw` in LLVM IR), since we know that the multiplication
                 // cannot signed wrap, and that both operands are non-negative. But at the time of writing,
-                // `BuilderMethods` can't do this, and it doesn't seem to enable any further optimizations.
+                // the `LLVM-C` binding can't do this, and it doesn't seem to enable any further optimizations.
                 bx.unchecked_smul(info.unwrap(), bx.const_usize(unit.size.bytes())),
                 bx.const_usize(unit.align.abi.bytes()),
             )
diff --git a/library/core/src/hash/mod.rs b/library/core/src/hash/mod.rs
index 71a0d1825ef..540831c8253 100644
--- a/library/core/src/hash/mod.rs
+++ b/library/core/src/hash/mod.rs
@@ -834,7 +834,7 @@ mod impls {
 
                 #[inline]
                 fn hash_slice<H: ~const Hasher>(data: &[$ty], state: &mut H) {
-                    let newlen = data.len() * mem::size_of::<$ty>();
+                    let newlen = mem::size_of_val(data);
                     let ptr = data.as_ptr() as *const u8;
                     // SAFETY: `ptr` is valid and aligned, as this macro is only used
                     // for numeric primitives which have no padding. The new slice only