about summary refs log tree commit diff
path: root/tests/coverage/attr/nested.coverage
diff options
context:
space:
mode:
authorThe Miri Cronjob Bot <miri@cron.bot>2024-06-19 05:02:35 +0000
committerThe Miri Cronjob Bot <miri@cron.bot>2024-06-19 05:02:35 +0000
commit3e93254d5e2efb3d2dd738833142de9274c7b191 (patch)
tree6ad18502b12564bac17108d771d900947abbefcb /tests/coverage/attr/nested.coverage
parentd9f1d557860138da64d52c0f536db395a99b9a4a (diff)
parent2a6a42329f79d3c2a42f23ca9fb68aba511a2bc1 (diff)
downloadrust-3e93254d5e2efb3d2dd738833142de9274c7b191.tar.gz
rust-3e93254d5e2efb3d2dd738833142de9274c7b191.zip
Merge from rustc
Diffstat (limited to 'tests/coverage/attr/nested.coverage')
-rw-r--r--tests/coverage/attr/nested.coverage111
1 files changed, 111 insertions, 0 deletions
diff --git a/tests/coverage/attr/nested.coverage b/tests/coverage/attr/nested.coverage
new file mode 100644
index 00000000000..13129572aec
--- /dev/null
+++ b/tests/coverage/attr/nested.coverage
@@ -0,0 +1,111 @@
+   LL|       |#![feature(coverage_attribute, stmt_expr_attributes)]
+   LL|       |//@ edition: 2021
+   LL|       |
+   LL|       |// Demonstrates the interaction between #[coverage(off)] and various kinds of
+   LL|       |// nested function.
+   LL|       |
+   LL|       |// FIXME(#126625): Coverage attributes should apply recursively to nested functions.
+   LL|       |// FIXME(#126626): When an inner (non-closure) function has `#[coverage(off)]`,
+   LL|       |// its lines can still be marked with misleading execution counts from its enclosing
+   LL|       |// function.
+   LL|       |
+   LL|       |#[coverage(off)]
+   LL|       |fn do_stuff() {}
+   LL|       |
+   LL|       |#[coverage(off)]
+   LL|       |fn outer_fn() {
+   LL|      0|    fn middle_fn() {
+   LL|      0|        fn inner_fn() {
+   LL|      0|            do_stuff();
+   LL|      0|        }
+   LL|      0|        do_stuff();
+   LL|      0|    }
+   LL|       |    do_stuff();
+   LL|       |}
+   LL|       |
+   LL|       |struct MyOuter;
+   LL|       |impl MyOuter {
+   LL|       |    #[coverage(off)]
+   LL|       |    fn outer_method(&self) {
+   LL|       |        struct MyMiddle;
+   LL|       |        impl MyMiddle {
+   LL|      0|            fn middle_method(&self) {
+   LL|      0|                struct MyInner;
+   LL|      0|                impl MyInner {
+   LL|      0|                    fn inner_method(&self) {
+   LL|      0|                        do_stuff();
+   LL|      0|                    }
+   LL|      0|                }
+   LL|      0|                do_stuff();
+   LL|      0|            }
+   LL|       |        }
+   LL|       |        do_stuff();
+   LL|       |    }
+   LL|       |}
+   LL|       |
+   LL|       |trait MyTrait {
+   LL|       |    fn trait_method(&self);
+   LL|       |}
+   LL|       |impl MyTrait for MyOuter {
+   LL|       |    #[coverage(off)]
+   LL|       |    fn trait_method(&self) {
+   LL|       |        struct MyMiddle;
+   LL|       |        impl MyTrait for MyMiddle {
+   LL|      0|            fn trait_method(&self) {
+   LL|      0|                struct MyInner;
+   LL|      0|                impl MyTrait for MyInner {
+   LL|      0|                    fn trait_method(&self) {
+   LL|      0|                        do_stuff();
+   LL|      0|                    }
+   LL|      0|                }
+   LL|      0|                do_stuff();
+   LL|      0|            }
+   LL|       |        }
+   LL|       |        do_stuff();
+   LL|       |    }
+   LL|       |}
+   LL|       |
+   LL|      1|fn closure_expr() {
+   LL|      1|    let _outer = #[coverage(off)]
+   LL|       |    || {
+   LL|      0|        let _middle = || {
+   LL|      0|            let _inner = || {
+   LL|      0|                do_stuff();
+   LL|      0|            };
+   LL|      0|            do_stuff();
+   LL|      0|        };
+   LL|       |        do_stuff();
+   LL|       |    };
+   LL|      1|    do_stuff();
+   LL|      1|}
+   LL|       |
+   LL|       |// This syntax is allowed, even without #![feature(stmt_expr_attributes)].
+   LL|      1|fn closure_tail() {
+   LL|      1|    let _outer = {
+   LL|       |        #[coverage(off)]
+   LL|       |        || {
+   LL|       |            let _middle = {
+   LL|      0|                || {
+   LL|      0|                    let _inner = {
+   LL|      0|                        || {
+   LL|      0|                            do_stuff();
+   LL|      0|                        }
+   LL|       |                    };
+   LL|      0|                    do_stuff();
+   LL|      0|                }
+   LL|       |            };
+   LL|       |            do_stuff();
+   LL|       |        }
+   LL|       |    };
+   LL|      1|    do_stuff();
+   LL|      1|}
+   LL|       |
+   LL|       |#[coverage(off)]
+   LL|       |fn main() {
+   LL|       |    outer_fn();
+   LL|       |    MyOuter.outer_method();
+   LL|       |    MyOuter.trait_method();
+   LL|       |    closure_expr();
+   LL|       |    closure_tail();
+   LL|       |}
+