about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThe 8472 <git@infinite-source.de>2023-01-02 05:17:47 +0100
committerThe 8472 <git@infinite-source.de>2023-06-12 13:03:29 +0200
commitcfb0f11a9f506292cd213872f759078d9302e0cc (patch)
tree82ff1937e5a61a511adbc72aafdec053b8a40ad9
parentfd0a3313f7a64cb16533030e49a271db449368c3 (diff)
downloadrust-cfb0f11a9f506292cd213872f759078d9302e0cc.tar.gz
rust-cfb0f11a9f506292cd213872f759078d9302e0cc.zip
add benchmark
-rw-r--r--library/core/benches/slice.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/library/core/benches/slice.rs b/library/core/benches/slice.rs
index 9b86a0ca97c..3bfb35e684e 100644
--- a/library/core/benches/slice.rs
+++ b/library/core/benches/slice.rs
@@ -1,3 +1,4 @@
+use core::ptr::NonNull;
 use test::black_box;
 use test::Bencher;
 
@@ -162,3 +163,11 @@ fn fill_byte_sized(b: &mut Bencher) {
         black_box(slice.fill(black_box(NewType(42))));
     });
 }
+
+// Tests the ability of the compiler to recognize that only the last slice item is needed
+// based on issue #106288
+#[bench]
+fn fold_to_last(b: &mut Bencher) {
+    let slice: &[i32] = &[0; 1024];
+    b.iter(|| black_box(slice).iter().fold(None, |_, r| Some(NonNull::from(r))));
+}