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.
38 lines
1.6 KiB
Plaintext
38 lines
1.6 KiB
Plaintext
LL| |//@ min-llvm-version: 23
|
|
LL| |#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
|
|
LL| |
|
|
LL| |use std::ops::{Coroutine, CoroutineState};
|
|
LL| |use std::pin::Pin;
|
|
LL| |
|
|
LL| |// The following implementation of a function called from a `yield` statement
|
|
LL| |// (apparently requiring the Result and the `String` type or constructor)
|
|
LL| |// creates conditions where the `coroutine::StateTransform` MIR transform will
|
|
LL| |// drop all `Counter` `Coverage` statements from a MIR. `simplify.rs` has logic
|
|
LL| |// to handle this condition, and still report dead block coverage.
|
|
LL| 1|fn get_u32(val: bool) -> Result<u32, String> {
|
|
LL| 1| if val {
|
|
LL| 1| Ok(1) //
|
|
LL| | } else {
|
|
LL| 0| Err(String::from("some error")) //
|
|
LL| | }
|
|
LL| 1|}
|
|
LL| |
|
|
LL| 1|fn main() {
|
|
LL| 1| let is_true = std::env::args().len() == 1;
|
|
LL| | let mut coroutine = #[coroutine]
|
|
LL| 1| || {
|
|
LL| 1| yield get_u32(is_true);
|
|
LL| 1| return "foo";
|
|
LL| 1| };
|
|
LL| |
|
|
LL| 1| match Pin::new(&mut coroutine).resume(()) {
|
|
LL| 1| CoroutineState::Yielded(Ok(1)) => {}
|
|
LL| 0| _ => panic!("unexpected return from resume"),
|
|
LL| | }
|
|
LL| 1| match Pin::new(&mut coroutine).resume(()) {
|
|
LL| 1| CoroutineState::Complete("foo") => {}
|
|
LL| 0| _ => panic!("unexpected return from resume"),
|
|
LL| | }
|
|
LL| 1|}
|
|
|