Tarpaulin: `core::hint::unreachable_unchecked()` is marked as uncovered.

Created on 22 Dec 2018  Â·  9Comments  Â·  Source: xd009642/tarpaulin

Sample report: codecov link

Lines with core::hint::unreachable_unchecked() are marked as untested.

Most helpful comment

@jonhoo your unreachable was because I wasn't going down into closures during source analysis. working on both of these things today :+1:

All 9 comments

unreachable! should also probably be ignored.

hmm unreachable should be ignored.. I'll look into it. And also cover the unreachable_unchecked

@jonhoo your unreachable was because I wasn't going down into closures during source analysis. working on both of these things today :+1:

Right both of these issues are now sorted in the source_analysis module with accompanying tests and merged into the develop branch.

unreachable_unchecked has a bit of extra nuance since I definitively tell if someone has an import that means they don't need the full path or whether someone else has defined a function with the same name in a different module. However, I filter any function called unreachable_unchecked because it seems common sense that people won't reuse names like that because of the potential confusion

So playing around with it a bit I encountered some weird behaviour, some sample code incoming:
src/lib.rs:

pub unsafe fn test() -> bool {
    let var1 = if std::env::args_os().count() > 0 {
        Some(())
    } else {
        None
    };

    if let Some(..) = var1 {
        true
    } else {
        core::hint::unreachable_unchecked()
    }
}

pub trait UncheckedUnwrap<T> {
    unsafe fn unchecked_unwrap(self) -> T;
}

impl<T, E: core::fmt::Debug> UncheckedUnwrap<T> for Result<T, E> {
    unsafe fn unchecked_unwrap(self) -> T {
        if let Ok(value) = self {
            value
        } else {
            core::hint::unreachable_unchecked()
        }
    }
}

tests/test.rs

use test_tarpaulin::UncheckedUnwrap;

#[test]
fn test() {
    unsafe { test_tarpaulin::test() };
}

#[test]

fn result_unwrap_success() {
    let result: Result<_, ()> = Ok(0);

    assert_eq!(unsafe { result.unchecked_unwrap() }, 0);
}
  • In test() the line true isn't marked, which doesn't happen if I don't use core::hint::unreachable_unchecked().
  • In unchecked_unwrap(self) the line } else { is marked as uncovered for some reason. I'm not sure why, but I wasn't able to reproduce this in other forms, like in test(). Again if I'm not using core::hint::unreachable_unchecked() this doesn't happen.

The } else { may just be a known issue in #136. As for the true, could you run tarpaulin with the --debug option so I can see the source analysis debug printout? I have a feeling I might know what this is

[TRACE tarpaulin] Debug mode activated
[INFO tarpaulin] Running Tarpaulin
[INFO tarpaulin] Building project
[DEBUG tarpaulin] Processing test
[INFO tarpaulin] Launching test
[INFO tarpaulin] running /home/***/rust/test-tarpaulin/target/debug/deps/test-52190221525e6021
[TRACE tarpaulin] Source analysis for tests/test.rs
[TRACE tarpaulin] Ignorable lines: [1, 2, 6, 7, 9, 12, 14]
[TRACE tarpaulin] Source analysis for src/lib.rs
[TRACE tarpaulin] Ignorable lines: [6, 7, 11, 12, 13, 14, 17, 18, 24, 25, 26, 27]
[TRACE tarpaulin] Coverable lines: [20, 21, 22, 23]
[TRACE tarpaulin] Adding trace at address 0x4035f7 in tests/test.rs:13
[TRACE tarpaulin] Adding trace at address 0x4035d0 in tests/test.rs:4
[TRACE tarpaulin] Adding trace at address 0x4035e0 in tests/test.rs:10
[TRACE tarpaulin] Adding trace at address 0x4035d1 in tests/test.rs:5
[TRACE tarpaulin] Adding trace at address 0x4035e7 in tests/test.rs:11
[TRACE tarpaulin] Adding trace at address 0x4037fe in src/lib.rs:22
[TRACE tarpaulin] Adding trace at address 0x4037d0 in src/lib.rs:20
[TRACE tarpaulin] Adding trace at address 0x4037dc in src/lib.rs:21
[TRACE tarpaulin] Adding trace at address 0x403840 in tests/test.rs:4
[TRACE tarpaulin] Adding trace at address 0x403860 in tests/test.rs:10
[TRACE tarpaulin] Adding trace at address 0x44556f in src/lib.rs:5
[TRACE tarpaulin] Adding trace at address 0x445568 in src/lib.rs:3
[TRACE tarpaulin] Adding trace at address 0x445540 in src/lib.rs:1
[TRACE tarpaulin] Adding trace at address 0x445574 in src/lib.rs:8
[TRACE tarpaulin] Adding trace at address 0x445544 in src/lib.rs:2
[TRACE tarpaulin] Adding trace at address 0x445a1b in src/lib.rs:1
[TRACE tarpaulin] Adding trace for potentially uncoverable line in src/lib.rs:23
[TRACE tarpaulin] Test PID is 2057
[TRACE tarpaulin] Caught inferior transitioning to Initialise state
[TRACE tarpaulin] Initialised inferior, transitioning to wait state

running 2 tests
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x403860
[TRACE tarpaulin] Incrementing hit count for trace
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x403860
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x4035e0
[TRACE tarpaulin] Incrementing hit count for trace
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x4035e6
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x4035e7
[TRACE tarpaulin] Incrementing hit count for trace
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x4035ee
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x4035f7
[TRACE tarpaulin] Incrementing hit count for trace
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x4035fa
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x4037d0
[TRACE tarpaulin] Incrementing hit count for trace
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x4037d3
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x4037dc
[TRACE tarpaulin] Incrementing hit count for trace
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x4037df
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x4037fe
[TRACE tarpaulin] Incrementing hit count for trace
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x403801
.[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x403840
[TRACE tarpaulin] Incrementing hit count for trace
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x403840
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x4035d0
[TRACE tarpaulin] Incrementing hit count for trace
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x4035d0
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x4035d1
[TRACE tarpaulin] Incrementing hit count for trace
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x44553f
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x445540
[TRACE tarpaulin] Incrementing hit count for trace
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x445543
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x445544
[TRACE tarpaulin] Incrementing hit count for trace
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x445548
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x445568
[TRACE tarpaulin] Incrementing hit count for trace
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x44556c
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x445574
[TRACE tarpaulin] Incrementing hit count for trace
[TRACE tarpaulin] Caught signal Stopped(Pid(2057), SIGTRAP)
[TRACE tarpaulin] Hit address 0x445577
.
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

[TRACE tarpaulin] Caught signal PtraceEvent(Pid(2057), SIGTRAP, 6)
[TRACE tarpaulin] Child exiting
[TRACE tarpaulin] Caught signal Exited(Pid(2057), 0)
[DEBUG tarpaulin] Processing test-tarpaulin
[INFO tarpaulin] Launching test
[INFO tarpaulin] running /home/***/rust/test-tarpaulin/target/debug/deps/test_tarpaulin-0e56ff0dca6b40f4
[TRACE tarpaulin] Source analysis for src/lib.rs
[TRACE tarpaulin] Ignorable lines: [6, 7, 11, 12, 13, 14, 17, 18, 24, 25, 26, 27]
[TRACE tarpaulin] Coverable lines: [20, 21, 22, 23]
[TRACE tarpaulin] Source analysis for tests/test.rs
[TRACE tarpaulin] Ignorable lines: [1, 2, 6, 7, 9, 12, 14]
[TRACE tarpaulin] Adding trace at address 0x40415b in src/lib.rs:1
[TRACE tarpaulin] Adding trace at address 0x404373 in src/lib.rs:8
[TRACE tarpaulin] Adding trace at address 0x404344 in src/lib.rs:2
[TRACE tarpaulin] Adding trace at address 0x40436e in src/lib.rs:5
[TRACE tarpaulin] Adding trace at address 0x404367 in src/lib.rs:3
[TRACE tarpaulin] Adding trace at address 0x404340 in src/lib.rs:1
[TRACE tarpaulin] Adding trace for potentially uncoverable line in src/lib.rs:21
[TRACE tarpaulin] Adding trace for potentially uncoverable line in src/lib.rs:20
[TRACE tarpaulin] Adding trace for potentially uncoverable line in src/lib.rs:22
[TRACE tarpaulin] Adding trace for potentially uncoverable line in src/lib.rs:23
[TRACE tarpaulin] Test PID is 2059
[TRACE tarpaulin] Caught inferior transitioning to Initialise state
[TRACE tarpaulin] Initialised inferior, transitioning to wait state

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

[TRACE tarpaulin] Caught signal PtraceEvent(Pid(2059), SIGTRAP, 6)
[TRACE tarpaulin] Child exiting
[TRACE tarpaulin] Caught signal Exited(Pid(2059), 0)
[INFO tarpaulin] Coverage Results:
|| Tested/Total Lines:
|| src/lib.rs: 7/9
|| tests/test.rs: 5/5
||
85.71% coverage, 12/14 lines covered

I'm going to close this as the core issue is solved and the remaining issues have been noted in other issues. Some progress but still figuring out a way to solve this that doesn't add any regressions in

Thanks for your hard work!

Was this page helpful?
0 / 5 - 0 ratings