1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
#![feature(coverage_attribute, stmt_expr_attributes)]
//@ edition: 2021
//@ reference: attributes.coverage.nesting
// Demonstrates the interaction between #[coverage(off)] and various kinds of
// nested function.
#[coverage(off)]
fn do_stuff() {}
#[coverage(off)]
fn outer_fn() {
fn middle_fn() {
fn inner_fn() {
do_stuff();
}
do_stuff();
}
do_stuff();
}
struct MyOuter;
impl MyOuter {
#[coverage(off)]
fn outer_method(&self) {
struct MyMiddle;
impl MyMiddle {
fn middle_method(&self) {
struct MyInner;
impl MyInner {
fn inner_method(&self) {
do_stuff();
}
}
do_stuff();
}
}
do_stuff();
}
}
trait MyTrait {
fn trait_method(&self);
}
impl MyTrait for MyOuter {
#[coverage(off)]
fn trait_method(&self) {
struct MyMiddle;
impl MyTrait for MyMiddle {
fn trait_method(&self) {
struct MyInner;
impl MyTrait for MyInner {
fn trait_method(&self) {
do_stuff();
}
}
do_stuff();
}
}
do_stuff();
}
}
fn closure_expr() {
let _outer = #[coverage(off)]
|| {
let _middle = || {
let _inner = || {
do_stuff();
};
do_stuff();
};
do_stuff();
};
do_stuff();
}
// This syntax is allowed, even without #![feature(stmt_expr_attributes)].
fn closure_tail() {
let _outer = {
#[coverage(off)]
|| {
let _middle = {
|| {
let _inner = {
|| {
do_stuff();
}
};
do_stuff();
}
};
do_stuff();
}
};
do_stuff();
}
#[coverage(off)]
fn main() {
outer_fn();
MyOuter.outer_method();
MyOuter.trait_method();
closure_expr();
closure_tail();
}
|