mirror of
https://github.com/allankoechke/rust.git
synced 2026-12-01 09:32:15 +00:00
Instead of trying to heuristically recover source-code spans from MIR soup, we can now take advantage of the `CoverageKind::Point` statements injected for specific HIR expressions. This is a transitional implementation that lets us remove the old MIR-soup code, but still relies heavily on the existing span-refinement heuristics, and does not take advantage of the full possibilities of HIR-aware coverage instrumentation. In order to avoid annoying never-executed spans in code that contains assertions, a heuristic has been added that ignores any expression within the arguments of a macro-expanded function call that returns `!`. Some coverage tests now require `//@ min-llvm-version: 23`, due to changes in how LLVM sorts the coverage mapping entries.
59 lines
2.0 KiB
Plaintext
59 lines
2.0 KiB
Plaintext
LL| |#![allow(unused_assignments, unused_variables, dead_code)]
|
|
LL| |
|
|
LL| 1|fn main() {
|
|
LL| | // Initialize test constants in a way that cannot be determined at compile time, to ensure
|
|
LL| | // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
|
|
LL| | // dependent conditions.
|
|
LL| 1| let is_true = std::env::args().len() == 1;
|
|
LL| |
|
|
LL| 1| let mut countdown = 0;
|
|
LL| 1| if is_true {
|
|
LL| 1| countdown = 10;
|
|
LL| 0| }
|
|
LL| |
|
|
LL| | mod in_mod {
|
|
LL| | const IN_MOD_CONST: u32 = 1000;
|
|
LL| | }
|
|
LL| |
|
|
LL| 3| fn in_func(a: u32) {
|
|
LL| 3| let b = 1;
|
|
LL| 3| let c = a + b;
|
|
LL| 3| println!("c = {}", c)
|
|
LL| 3| }
|
|
LL| |
|
|
LL| | struct InStruct {
|
|
LL| | in_struct_field: u32,
|
|
LL| | }
|
|
LL| |
|
|
LL| | const IN_CONST: u32 = 1234;
|
|
LL| |
|
|
LL| | trait InTrait {
|
|
LL| | fn trait_func(&mut self, incr: u32);
|
|
LL| |
|
|
LL| 1| fn default_trait_func(&mut self) {
|
|
LL| 1| in_func(IN_CONST);
|
|
LL| 1| self.trait_func(IN_CONST);
|
|
LL| 1| }
|
|
LL| | }
|
|
LL| |
|
|
LL| | impl InTrait for InStruct {
|
|
LL| 1| fn trait_func(&mut self, incr: u32) {
|
|
LL| 1| self.in_struct_field += incr;
|
|
LL| 1| in_func(self.in_struct_field);
|
|
LL| 1| }
|
|
LL| | }
|
|
LL| |
|
|
LL| | type InType = String;
|
|
LL| |
|
|
LL| 1| if is_true {
|
|
LL| 1| in_func(countdown);
|
|
LL| 0| }
|
|
LL| |
|
|
LL| 1| let mut val = InStruct {
|
|
LL| 1| in_struct_field: 101, //
|
|
LL| 1| };
|
|
LL| |
|
|
LL| 1| val.default_trait_func();
|
|
LL| 1|}
|
|
|