]> git.lizzy.rs Git - rust.git/blob - tests/run-make/coverage/inline.rs
Merge commit '7f27e2e74ef957baa382dc05cf08df6368165c74' into clippyup
[rust.git] / tests / run-make / coverage / inline.rs
1 // compile-flags: -Zinline-mir
2
3 use std::fmt::Display;
4
5 fn main() {
6     permutations(&['a', 'b', 'c']);
7 }
8
9 #[inline(always)]
10 fn permutations<T: Copy + Display>(xs: &[T]) {
11     let mut ys = xs.to_owned();
12     permutate(&mut ys, 0);
13 }
14
15 fn permutate<T: Copy + Display>(xs: &mut [T], k: usize) {
16     let n = length(xs);
17     if k == n {
18         display(xs);
19     } else if k < n {
20         for i in k..n {
21             swap(xs, i, k);
22             permutate(xs, k + 1);
23             swap(xs, i, k);
24         }
25     } else {
26         error();
27     }
28 }
29
30 fn length<T>(xs: &[T]) -> usize {
31     xs.len()
32 }
33
34 #[inline]
35 fn swap<T: Copy>(xs: &mut [T], i: usize, j: usize) {
36     let t = xs[i];
37     xs[i] = xs[j];
38     xs[j] = t;
39 }
40
41 fn display<T: Display>(xs: &[T]) {
42     for x in xs {
43         print!("{}", x);
44     }
45     println!();
46 }
47
48 #[inline(always)]
49 fn error() {
50     panic!("error");
51 }