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

xd009642 / tarpaulin / #483

10 May 2024 10:16PM UTC coverage: 73.61% (-0.6%) from 74.182%
#483

push

xd009642
Release 0.30.0

89 of 102 new or added lines in 7 files covered. (87.25%)

7 existing lines in 6 files now uncovered.

2569 of 3490 relevant lines covered (73.61%)

143183.62 hits per line

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

83.02
/src/source_analysis/statements.rs
1
use crate::source_analysis::prelude::*;
2
use syn::*;
3

4
impl SourceAnalysis {
5
    pub(crate) fn process_statements(&mut self, stmts: &[Stmt], ctx: &Context) -> SubResult {
626✔
6
        // in a list of statements, if any of them is unreachable, the whole list is
7
        // unreachable
8
        let mut unreachable = false;
626✔
9
        let mut definite = false;
626✔
10
        for stmt in stmts.iter() {
1,608✔
11
            let res = match stmt {
1,964✔
12
                Stmt::Item(i) => self.process_items(&[i.clone()], ctx),
4✔
13
                Stmt::Expr(i, _) => self.process_expr(i, ctx),
612✔
14
                Stmt::Local(i) => self.process_local(i, ctx),
183✔
15
                Stmt::Macro(i) => self.process_macro(i, ctx),
183✔
16
            };
17
            unreachable |= res.is_unreachable();
18
            if SubResult::Definite == res {
101✔
19
                definite = true;
101✔
20
            }
21
        }
22
        // We must be in a block, the parent will handle marking the span as unreachable
23
        if unreachable && !definite {
645✔
24
            SubResult::Unreachable
14✔
25
        } else if definite {
612✔
26
            SubResult::Definite
69✔
27
        } else {
28
            SubResult::Ok
543✔
29
        }
30
    }
31

32
    fn process_macro(&mut self, mac: &StmtMacro, ctx: &Context) -> SubResult {
183✔
33
        let check_cover = self.check_attr_list(&mac.attrs, ctx);
183✔
34
        if check_cover {
183✔
35
            if let Some(macro_name) = mac.mac.path.segments.last() {
366✔
36
                let (sub, should_ignore) = ignore_macro_name(&macro_name.ident, ctx);
37
                let analysis = self.get_line_analysis(ctx.file.to_path_buf());
38
                if should_ignore {
15✔
39
                    analysis.ignore_tokens(mac);
15✔
40
                } else {
41
                    // lets just merge the macros into one big logical line
42
                    let start = mac.span().start().line;
168✔
43
                    for i in start..mac.span().end().line {
8✔
44
                        analysis.logical_lines.insert(i + 1, start);
4✔
45
                    }
46
                }
47
                sub
183✔
48
            } else {
NEW
49
                SubResult::Ok
×
50
            }
51
        } else {
NEW
52
            let analysis = self.get_line_analysis(ctx.file.to_path_buf());
×
NEW
53
            analysis.ignore_tokens(mac);
×
NEW
54
            SubResult::Ok
×
55
        }
56
    }
57

58
    fn process_local(&mut self, local: &Local, ctx: &Context) -> SubResult {
183✔
59
        let mut result = SubResult::Ok;
183✔
60
        if let Some(init) = &local.init {
366✔
61
            // Process if the local wasn't ignored with an attribute
62
            let check_cover = self.check_attr_list(&local.attrs, ctx);
63
            let analysis = self.get_line_analysis(ctx.file.to_path_buf());
64

65
            if check_cover {
66
                for a in &local.attrs {
183✔
67
                    analysis.ignore_tokens(a);
×
68
                }
69
                let spn = local.span();
183✔
70
                let base_line = local.let_token.span().start().line;
183✔
71
                if base_line != spn.end().line {
183✔
72
                    // Now check the other lines
73
                    let lhs = local.pat.span();
36✔
74
                    if lhs.start().line != base_line {
36✔
75
                        analysis.logical_lines.insert(lhs.start().line, base_line);
×
76
                    }
77
                    let eq = init.eq_token.span();
36✔
78
                    if eq.start().line != base_line {
45✔
79
                        analysis.logical_lines.insert(eq.start().line, base_line);
9✔
80
                    }
81
                    if init.expr.span().start().line != base_line {
51✔
82
                        analysis
15✔
83
                            .logical_lines
15✔
84
                            .insert(init.expr.span().start().line, base_line);
15✔
85
                    }
86
                    result += self.process_expr(&init.expr, ctx);
36✔
NEW
87
                    if let Some((_, expr)) = &init.diverge {
×
NEW
88
                        self.process_expr(expr, ctx);
×
89
                    }
90
                }
91
            } else {
92
                analysis.ignore_tokens(local);
×
93
            }
94
        }
95
        result
183✔
96
    }
97
}
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