• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

xd009642 / tarpaulin / #644

20 May 2025 06:46AM UTC coverage: 76.57% (-1.9%) from 78.457%
#644

push

xd009642
Release 0.32.6

3925 of 5126 relevant lines covered (76.57%)

134559.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.23
/src/source_analysis/macros.rs
1
use crate::source_analysis::prelude::*;
2
use proc_macro2::TokenTree;
3
use std::cmp::{max, min};
4
use std::ops::Range;
5
use syn::*;
6

7
pub fn ignore_macro_name(ident: &Ident, ctx: &Context) -> (SubResult, bool) {
225✔
8
    let ident_s = ident.to_string();
675✔
9
    let unreachable = ident == "unreachable";
450✔
10
    let standard_ignores =
225✔
11
        ident == "unimplemented" || ident == "include" || ident == "cfg" || ident == "todo";
897✔
12
    let ignore_panic = ctx.config.ignore_panics
450✔
13
        && (ident == "panic"
3✔
14
            || ident_s.starts_with("assert")
2✔
15
            || ident_s.starts_with("debug_assert"));
1✔
16
    let sub = if unreachable {
450✔
17
        SubResult::Unreachable
16✔
18
    } else {
19
        SubResult::Ok
209✔
20
    };
21
    let should_ignore = standard_ignores || ignore_panic || unreachable;
883✔
22
    (sub, should_ignore)
225✔
23
}
24

25
impl SourceAnalysis {
26
    pub(crate) fn visit_macro_call(&mut self, mac: &Macro, ctx: &Context) -> SubResult {
37✔
27
        let analysis = self.get_line_analysis(ctx.file.to_path_buf());
185✔
28
        let mut skip = false;
74✔
29
        if let Some(PathSegment {
30
            ref ident,
37✔
31
            arguments: _,
32
        }) = mac.path.segments.last()
37✔
33
        {
34
            let (sub, ignore_macro) = ignore_macro_name(ident, ctx);
35
            if ignore_macro {
11✔
36
                analysis.ignore_tokens(mac);
33✔
37
                skip = true;
11✔
38
            }
39
            if sub == SubResult::Unreachable {
40
                return SubResult::Unreachable;
8✔
41
            }
42
        }
43
        if !skip {
29✔
44
            let start = mac.span().start().line + 1;
26✔
45
            let range = get_line_range(mac);
46
            let lines = process_mac_args(&mac.tokens);
47
            let lines = (start..range.end).filter(|x| !lines.contains(x));
×
48
            analysis.add_to_ignore(lines);
49
        }
50
        SubResult::Ok
51
    }
52
}
53

54
pub(crate) fn get_line_range<T>(tokens: T) -> Range<usize>
174✔
55
where
56
    T: ToTokens,
57
{
58
    let mut start = None;
348✔
59
    let mut end = None;
348✔
60
    for token in tokens.into_token_stream() {
1,120✔
61
        let temp_start = token.span().start().line;
×
62
        let temp_end = token.span().end().line + 1;
×
63
        start = match start {
×
64
            Some(x) => Some(min(temp_start, x)),
1,794✔
65
            None => Some(temp_start),
174✔
66
        };
67
        end = match end {
×
68
            Some(x) => Some(max(temp_end, x)),
1,794✔
69
            None => Some(temp_end),
174✔
70
        };
71
    }
72
    match (start, end) {
348✔
73
        (Some(s), Some(e)) => s..e,
174✔
74
        _ => 0..0,
×
75
    }
76
}
77

78
fn process_mac_args(tokens: &TokenStream) -> HashSet<usize> {
26✔
79
    let mut cover: HashSet<usize> = HashSet::new();
78✔
80
    // IntoIter not implemented for &TokenStream.
81
    for token in tokens.clone() {
87✔
82
        match token {
83
            TokenTree::Literal(_) | TokenTree::Punct { .. } => {}
18✔
84
            _ => {
85
                for i in get_line_range(token) {
51✔
86
                    cover.insert(i);
87
                }
88
            }
89
        }
90
    }
91
    cover
26✔
92
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc