Coverage Report

Created: 2026-02-14 07:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/more-asserts-0.3.1/src/inner.rs
Line
Count
Source
1
//! Outlined format+panic code.
2
//!
3
//! This reduces the code bloat caused by our macros, improving performance in
4
//! the case that the assertions are not triggered.
5
use core::fmt;
6
7
#[repr(u8)]
8
#[derive(Copy, Clone, PartialEq, Eq)]
9
#[doc(hidden)]
10
pub enum AssertType {
11
    Lt,
12
    Gt,
13
    Le,
14
    Ge,
15
    // TODO: `matches`? `contains`?
16
}
17
18
#[cold]
19
#[track_caller]
20
0
pub(crate) fn assert_failed_nomsg_impl(
21
0
    left: &dyn fmt::Debug,
22
0
    right: &dyn fmt::Debug,
23
0
    ty: AssertType,
24
0
) -> ! {
25
0
    assert_failed_impl(left, right, ty, None);
26
}
27
28
#[cold]
29
#[track_caller]
30
0
pub(crate) fn assert_failed_msg_impl(
31
0
    left: &dyn fmt::Debug,
32
0
    right: &dyn fmt::Debug,
33
0
    ty: AssertType,
34
0
    msg: fmt::Arguments<'_>,
35
0
) -> ! {
36
0
    assert_failed_impl(left, right, ty, Some(msg))
37
}
38
39
#[cold]
40
#[track_caller]
41
#[inline(never)]
42
0
fn assert_failed_impl(
43
0
    left: &dyn fmt::Debug,
44
0
    right: &dyn fmt::Debug,
45
0
    ty: AssertType,
46
0
    msg: Option<fmt::Arguments<'_>>,
47
0
) -> ! {
48
0
    let compare = match ty {
49
0
        AssertType::Lt => "<",
50
0
        AssertType::Gt => ">",
51
0
        AssertType::Le => "<=",
52
0
        AssertType::Ge => ">=",
53
    };
54
0
    if let Some(msg) = msg {
55
0
        panic!(
56
            "assertion failed: `(left {} right)`\n  left: `{:?}`,\n right: `{:?}`: {}",
57
            compare, left, right, msg,
58
        );
59
    } else {
60
0
        panic!(
61
            "assertion failed: `(left {} right)`\n  left: `{:?}`,\n right: `{:?}`",
62
            compare, left, right,
63
        );
64
    }
65
}