diff --git a/tests/coverage/closure_unit_return.cov-map b/tests/coverage/closure_unit_return.cov-map new file mode 100644 index 00000000000..330a6b420b0 --- /dev/null +++ b/tests/coverage/closure_unit_return.cov-map @@ -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) + diff --git a/tests/coverage/closure_unit_return.coverage b/tests/coverage/closure_unit_return.coverage new file mode 100644 index 00000000000..1a706b3a18d --- /dev/null +++ b/tests/coverage/closure_unit_return.coverage @@ -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| |} + diff --git a/tests/coverage/closure_unit_return.rs b/tests/coverage/closure_unit_return.rs new file mode 100644 index 00000000000..d2b4ab8bd9f --- /dev/null +++ b/tests/coverage/closure_unit_return.rs @@ -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(); +}