rust/tests/coverage-map/status-quo/inline.rs
Zalathar 3141177995 Copy most of tests/run-coverage into tests/coverage-map/status-quo
The output of these tests is too complicated to comfortably verify by hand, but
we can still use them to observe changes to the underlying mappings produced by
codegen/LLVM.

If these tests fail due to non-coverage changes (e.g. in HIR-to-MIR lowering or
MIR optimizations), it should usually be OK to just `--bless` them, as long as
the `run-coverage` test suite still works.
2023-09-05 11:55:34 +10:00

52 lines
864 B
Rust

// compile-flags: -Zinline-mir
use std::fmt::Display;
fn main() {
permutations(&['a', 'b', 'c']);
}
#[inline(always)]
fn permutations<T: Copy + Display>(xs: &[T]) {
let mut ys = xs.to_owned();
permutate(&mut ys, 0);
}
fn permutate<T: Copy + Display>(xs: &mut [T], k: usize) {
let n = length(xs);
if k == n {
display(xs);
} else if k < n {
for i in k..n {
swap(xs, i, k);
permutate(xs, k + 1);
swap(xs, i, k);
}
} else {
error();
}
}
fn length<T>(xs: &[T]) -> usize {
xs.len()
}
#[inline]
fn swap<T: Copy>(xs: &mut [T], i: usize, j: usize) {
let t = xs[i];
xs[i] = xs[j];
xs[j] = t;
}
fn display<T: Display>(xs: &[T]) {
for x in xs {
print!("{}", x);
}
println!();
}
#[inline(always)]
fn error() {
panic!("error");
}