]> git.proxmox.com Git - rustc.git/blob - tests/mir-opt/pre-codegen/slice_iter.rs
New upstream version 1.72.1+dfsg1
[rustc.git] / tests / mir-opt / pre-codegen / slice_iter.rs
1 // compile-flags: -O -C debuginfo=0 -Zmir-opt-level=2
2 // only-64bit
3 // ignore-debug
4 // EMIT_MIR_FOR_EACH_PANIC_STRATEGY
5
6 #![crate_type = "lib"]
7
8 // When this test was added, the MIR for `next` was 174 lines just for the basic
9 // blocks -- far more if you counted the scopes. The goal of having this here
10 // is to hopefully keep it a reasonable size, ideally eventually small enough
11 // that the mir inliner would actually be willing to inline it, since it's an
12 // important building block and usually very few *backend* instructions.
13
14 // As such, feel free to `--bless` whatever changes you get here, so long as
15 // doing so doesn't add substantially more MIR.
16
17 // EMIT_MIR slice_iter.slice_iter_next.PreCodegen.after.mir
18 pub fn slice_iter_next<'a, T>(it: &mut std::slice::Iter<'a, T>) -> Option<&'a T> {
19 it.next()
20 }
21
22 // EMIT_MIR slice_iter.slice_iter_mut_next_back.PreCodegen.after.mir
23 pub fn slice_iter_mut_next_back<'a, T>(it: &mut std::slice::IterMut<'a, T>) -> Option<&'a mut T> {
24 it.next_back()
25 }
26
27 // EMIT_MIR slice_iter.forward_loop.PreCodegen.after.mir
28 pub fn forward_loop<'a, T>(slice: &'a [T], f: impl Fn(&T)) {
29 for x in slice.iter() {
30 f(x)
31 }
32 }
33
34 // EMIT_MIR slice_iter.reverse_loop.PreCodegen.after.mir
35 pub fn reverse_loop<'a, T>(slice: &'a [T], f: impl Fn(&T)) {
36 for x in slice.iter().rev() {
37 f(x)
38 }
39 }
40
41 // EMIT_MIR slice_iter.enumerated_loop.PreCodegen.after.mir
42 pub fn enumerated_loop<'a, T>(slice: &'a [T], f: impl Fn(usize, &T)) {
43 for (i, x) in slice.iter().enumerate() {
44 f(i, x)
45 }
46 }
47
48 // EMIT_MIR slice_iter.range_loop.PreCodegen.after.mir
49 pub fn range_loop<'a, T>(slice: &'a [T], f: impl Fn(usize, &T)) {
50 for i in 0..slice.len() {
51 let x = &slice[i];
52 f(i, x)
53 }
54 }