forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#121135 - Zalathar:no-whole-body-span, r=wesleywiser coverage: Discard spans that fill the entire function body While debugging some other coverage changes, I discovered a frustrating inconsistency that occurs in functions containing closures, if they end with an implicit `()` return instead of an explicit trailing-expression. This turns out to have been caused by the corresponding node in MIR having a span that covers the entire function body. When preparing coverage spans, any span that fills the whole body tends to cause more harm than good, so this PR detects and discards those spans. (This isn't the first time whole-body spans have caused problems; we also eliminated some of them in rust-lang#118525.)
- Loading branch information
Showing
11 changed files
with
117 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, 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 + 16, 1) to (start + 1, 16) | ||
- Code(Counter(0)) at (prev + 5, 5) to (start + 2, 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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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| 0| }; | ||
LL| | | ||
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| |} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters