We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fd0a331 commit cfb0f11Copy full SHA for cfb0f11
library/core/benches/slice.rs
@@ -1,3 +1,4 @@
1
+use core::ptr::NonNull;
2
use test::black_box;
3
use test::Bencher;
4
@@ -162,3 +163,11 @@ fn fill_byte_sized(b: &mut Bencher) {
162
163
black_box(slice.fill(black_box(NewType(42))));
164
});
165
}
166
+
167
+// Tests the ability of the compiler to recognize that only the last slice item is needed
168
+// based on issue #106288
169
+#[bench]
170
+fn fold_to_last(b: &mut Bencher) {
171
+ let slice: &[i32] = &[0; 1024];
172
+ b.iter(|| black_box(slice).iter().fold(None, |_, r| Some(NonNull::from(r))));
173
+}
0 commit comments