4 // It's interesting to speculate if there is a way to leverage the Drop trait functionality
5 // to increment counters when a scope is closed, but I don't think it would help "out of the box".
7 // A `return` or `break` with expression might not need a temp value expression wrapper
8 // such as `return { let _t = result_expression; __incr_counter(...); _t };`
10 // ... **if** the __incr_counter() was somehow called from a "drop()" trait function.
12 // The problem is, since the drop call is automatic, there is no way to have argument variants
13 // depending on where the drop() occurs (e.g., from a `return` statement vs. from the end of
14 // the function). We need 2 different code regions though.
21 pub fn __incr_cov<T>(_region_loc: &str, /*index: u32,*/ result: T) -> T {
22 // println!("from: {}", _region_loc);
30 impl Drop for Firework {
32 println!("BOOM times {}!!!", self.strength);
33 __incr_cov("start of drop()", ());
37 fn main() -> Result<(),u8> {
38 let _firecracker = Firework { strength: 1 };
40 if __incr_cov("start of main()", true) {
41 return __incr_cov("if true", { let _t = Err(1); println!("computing return value"); _t });
44 let _tnt = Firework { strength: 100 };
45 // __incr_cov("after if block", Ok(())) // CAN USE COUNTER EXPRESSION: "start of drop()" - "if true"
49 // OUTPUT WHEN RUNNING THIS PROGRAM IS AS EXPECTED:
51 // computing return value