diff options
| author | Zalathar <Zalathar@users.noreply.github.com> | 2023-12-12 12:55:40 +1100 |
|---|---|---|
| committer | Zalathar <Zalathar@users.noreply.github.com> | 2023-12-16 11:10:11 +1100 |
| commit | e0de1439708d72a319ca334ef1d3237a7a4a6800 (patch) | |
| tree | 9e60383aec874585966bd5f7f67b359e965c0fa1 | |
| parent | c57f28bbf75572e10c6165c33a2aef922315fdb4 (diff) | |
| download | rust-e0de1439708d72a319ca334ef1d3237a7a4a6800.tar.gz rust-e0de1439708d72a319ca334ef1d3237a7a4a6800.zip | |
coverage: Regression test for markers in a function with no spans
| -rw-r--r-- | tests/coverage/no_spans_if_not.cov-map | 8 | ||||
| -rw-r--r-- | tests/coverage/no_spans_if_not.coverage | 30 | ||||
| -rw-r--r-- | tests/coverage/no_spans_if_not.rs | 29 |
3 files changed, 67 insertions, 0 deletions
diff --git a/tests/coverage/no_spans_if_not.cov-map b/tests/coverage/no_spans_if_not.cov-map new file mode 100644 index 00000000000..5277267ec1b --- /dev/null +++ b/tests/coverage/no_spans_if_not.cov-map @@ -0,0 +1,8 @@ +Function name: no_spans_if_not::main +Raw bytes (9): 0x[01, 01, 00, 01, 01, 0b, 01, 02, 02] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 11, 1) to (start + 2, 2) + diff --git a/tests/coverage/no_spans_if_not.coverage b/tests/coverage/no_spans_if_not.coverage new file mode 100644 index 00000000000..1b6bbc75a04 --- /dev/null +++ b/tests/coverage/no_spans_if_not.coverage @@ -0,0 +1,30 @@ + LL| |// edition: 2021 + LL| | + LL| |// If the span extractor can't find any relevant spans for a function, + LL| |// but the function contains coverage span-marker statements (e.g. inserted + LL| |// for `if !`), coverage codegen may think that it is instrumented and + LL| |// consequently complain that it has no spans. + LL| |// + LL| |// Regression test for <https://github.com/rust-lang/rust/issues/118850>, + LL| |// "A used function should have had coverage mapping data but did not". + LL| | + LL| 1|fn main() { + LL| 1| affected_function(); + LL| 1|} + LL| | + LL| |macro_rules! macro_that_defines_a_function { + LL| | (fn $name:ident () $body:tt) => { + LL| | fn $name () $body + LL| | } + LL| |} + LL| | + LL| |macro_that_defines_a_function! { + LL| | fn affected_function() { + LL| | if !false { + LL| | () + LL| | } else { + LL| | () + LL| | } + LL| | } + LL| |} + diff --git a/tests/coverage/no_spans_if_not.rs b/tests/coverage/no_spans_if_not.rs new file mode 100644 index 00000000000..2bbdc11cd5e --- /dev/null +++ b/tests/coverage/no_spans_if_not.rs @@ -0,0 +1,29 @@ +// edition: 2021 + +// If the span extractor can't find any relevant spans for a function, +// but the function contains coverage span-marker statements (e.g. inserted +// for `if !`), coverage codegen may think that it is instrumented and +// consequently complain that it has no spans. +// +// Regression test for <https://github.com/rust-lang/rust/issues/118850>, +// "A used function should have had coverage mapping data but did not". + +fn main() { + affected_function(); +} + +macro_rules! macro_that_defines_a_function { + (fn $name:ident () $body:tt) => { + fn $name () $body + } +} + +macro_that_defines_a_function! { + fn affected_function() { + if !false { + () + } else { + () + } + } +} |
