mirror of
https://github.com/allankoechke/rust.git
synced 2026-11-30 11:05:36 +00:00
Instead of trying to heuristically recover source-code spans from MIR soup, we can now take advantage of the `CoverageKind::Point` statements injected for specific HIR expressions. This is a transitional implementation that lets us remove the old MIR-soup code, but still relies heavily on the existing span-refinement heuristics, and does not take advantage of the full possibilities of HIR-aware coverage instrumentation. In order to avoid annoying never-executed spans in code that contains assertions, a heuristic has been added that ignores any expression within the arguments of a macro-expanded function call that returns `!`. Some coverage tests now require `//@ min-llvm-version: 23`, due to changes in how LLVM sorts the coverage mapping entries.
54 lines
1.6 KiB
Plaintext
54 lines
1.6 KiB
Plaintext
LL| |//@ compile-flags: -Zinline-mir
|
|
LL| |//@ min-llvm-version: 23
|
|
LL| |
|
|
LL| |use std::fmt::Display;
|
|
LL| |
|
|
LL| 1|fn main() {
|
|
LL| 1| permutations(&['a', 'b', 'c']);
|
|
LL| 1|}
|
|
LL| |
|
|
LL| |#[inline(always)]
|
|
LL| 1|fn permutations<T: Copy + Display>(xs: &[T]) {
|
|
LL| 1| let mut ys = xs.to_owned();
|
|
LL| 1| permutate(&mut ys, 0);
|
|
LL| 1|}
|
|
LL| |
|
|
LL| 16|fn permutate<T: Copy + Display>(xs: &mut [T], k: usize) {
|
|
LL| 16| let n = length(xs);
|
|
LL| 16| if k == n {
|
|
LL| 6| display(xs);
|
|
LL| 10| } else if k < n {
|
|
LL| 10| for i in k..n {
|
|
LL| 15| swap(xs, i, k);
|
|
LL| 15| permutate(xs, k + 1);
|
|
LL| 15| swap(xs, i, k);
|
|
LL| | }
|
|
LL| | } else {
|
|
LL| 0| error();
|
|
LL| | }
|
|
LL| 16|}
|
|
LL| |
|
|
LL| 16|fn length<T>(xs: &[T]) -> usize {
|
|
LL| 16| xs.len()
|
|
LL| 16|}
|
|
LL| |
|
|
LL| |#[inline]
|
|
LL| 30|fn swap<T: Copy>(xs: &mut [T], i: usize, j: usize) {
|
|
LL| 30| let t = xs[i];
|
|
LL| 30| xs[i] = xs[j];
|
|
LL| 30| xs[j] = t;
|
|
LL| 30|}
|
|
LL| |
|
|
LL| 6|fn display<T: Display>(xs: &[T]) {
|
|
LL| 6| for x in xs {
|
|
LL| 18| print!("{}", x);
|
|
LL| | }
|
|
LL| 6| println!();
|
|
LL| 6|}
|
|
LL| |
|
|
LL| |#[inline(always)]
|
|
LL| 0|fn error() {
|
|
LL| 0| panic!("error");
|
|
LL| |}
|
|
|