Skip to content

Commit

Permalink
coverage: Regression test for a span extraction inconsistency
Browse files Browse the repository at this point in the history
  • Loading branch information
Zalathar committed Feb 15, 2024
1 parent a447249 commit 75af3c5
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/coverage/closure_unit_return.cov-map
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Function name: closure_unit_return::explicit_unit
Raw bytes (14): 0x[01, 01, 00, 02, 01, 07, 01, 01, 10, 01, 05, 05, 02, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 2
- Code(Counter(0)) at (prev + 7, 1) to (start + 1, 16)
- Code(Counter(0)) at (prev + 5, 5) to (start + 2, 2)

Function name: closure_unit_return::explicit_unit::{closure#0} (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 00, 08, 16, 02, 06]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Zero) at (prev + 8, 22) to (start + 2, 6)

Function name: closure_unit_return::implicit_unit
Raw bytes (14): 0x[01, 01, 00, 02, 01, 10, 01, 01, 13, 01, 03, 06, 04, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 2
- Code(Counter(0)) at (prev + 16, 1) to (start + 1, 19)
- Code(Counter(0)) at (prev + 3, 6) to (start + 4, 2)

Function name: closure_unit_return::implicit_unit::{closure#0} (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 00, 11, 16, 02, 06]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Zero) at (prev + 17, 22) to (start + 2, 6)

30 changes: 30 additions & 0 deletions tests/coverage/closure_unit_return.coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
LL| |#![feature(coverage_attribute)]
LL| |// edition: 2021
LL| |
LL| |// Regression test for an inconsistency between functions that return the value
LL| |// of their trailing expression, and functions that implicitly return `()`.
LL| |
LL| 1|fn explicit_unit() {
LL| 1| let closure = || {
LL| 0| ();
LL| 0| };
LL| |
LL| 1| drop(closure);
LL| 1| () // explicit return of trailing value
LL| 1|}
LL| |
LL| 1|fn implicit_unit() {
LL| 1| let closure = || {
LL| 0| ();
LL| 1| };
LL| 1|
LL| 1| drop(closure);
LL| 1| // implicit return of `()`
LL| 1|}
LL| |
LL| |#[coverage(off)]
LL| |fn main() {
LL| | explicit_unit();
LL| | implicit_unit();
LL| |}

29 changes: 29 additions & 0 deletions tests/coverage/closure_unit_return.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#![feature(coverage_attribute)]
// edition: 2021

// Regression test for an inconsistency between functions that return the value
// of their trailing expression, and functions that implicitly return `()`.

fn explicit_unit() {
let closure = || {
();
};

drop(closure);
() // explicit return of trailing value
}

fn implicit_unit() {
let closure = || {
();
};

drop(closure);
// implicit return of `()`
}

#[coverage(off)]
fn main() {
explicit_unit();
implicit_unit();
}

0 comments on commit 75af3c5

Please sign in to comment.