diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
commit | c23a457e72abe608715ac76f076f47dc42af07a5 (patch) | |
tree | 2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /tests/run-coverage | |
parent | Releasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/run-coverage')
51 files changed, 303 insertions, 158 deletions
diff --git a/tests/run-coverage/assert.coverage b/tests/run-coverage/assert.coverage index 3c6108e43..8b997724c 100644 --- a/tests/run-coverage/assert.coverage +++ b/tests/run-coverage/assert.coverage @@ -7,7 +7,7 @@ ^1 LL| 3|} LL| | - LL| 1|fn main() -> Result<(),u8> { + LL| 1|fn main() -> Result<(), u8> { LL| 1| let mut countdown = 10; LL| 11| while countdown > 0 { LL| 11| if countdown == 1 { diff --git a/tests/run-coverage/assert.rs b/tests/run-coverage/assert.rs index d32a37e07..85e6662a6 100644 --- a/tests/run-coverage/assert.rs +++ b/tests/run-coverage/assert.rs @@ -6,7 +6,7 @@ fn might_fail_assert(one_plus_one: u32) { assert_eq!(1 + 1, one_plus_one, "the argument was wrong"); } -fn main() -> Result<(),u8> { +fn main() -> Result<(), u8> { let mut countdown = 10; while countdown > 0 { if countdown == 1 { diff --git a/tests/run-coverage/async2.coverage b/tests/run-coverage/async2.coverage index 7e0139ae0..fcb0a3aed 100644 --- a/tests/run-coverage/async2.coverage +++ b/tests/run-coverage/async2.coverage @@ -1,11 +1,5 @@ LL| |// compile-flags: --edition=2018 LL| | - LL| |use core::{ - LL| | future::Future, - LL| | marker::Send, - LL| | pin::Pin, - LL| |}; - LL| | LL| 1|fn non_async_func() { LL| 1| println!("non_async_func was covered"); LL| 1| let b = true; @@ -15,9 +9,6 @@ ^0 LL| 1|} LL| | - LL| | - LL| | - LL| | LL| 1|async fn async_func() { LL| 1| println!("async_func was covered"); LL| 1| let b = true; @@ -27,9 +18,6 @@ ^0 LL| 1|} LL| | - LL| | - LL| | - LL| | LL| 1|async fn async_func_just_println() { LL| 1| println!("async_func_just_println was covered"); LL| 1|} diff --git a/tests/run-coverage/async2.rs b/tests/run-coverage/async2.rs index 959d48ce9..2884ff297 100644 --- a/tests/run-coverage/async2.rs +++ b/tests/run-coverage/async2.rs @@ -1,11 +1,5 @@ // compile-flags: --edition=2018 -use core::{ - future::Future, - marker::Send, - pin::Pin, -}; - fn non_async_func() { println!("non_async_func was covered"); let b = true; @@ -14,9 +8,6 @@ fn non_async_func() { } } - - - async fn async_func() { println!("async_func was covered"); let b = true; @@ -25,9 +16,6 @@ async fn async_func() { } } - - - async fn async_func_just_println() { println!("async_func_just_println was covered"); } diff --git a/tests/run-coverage/auxiliary/inline_always_with_dead_code.rs b/tests/run-coverage/auxiliary/inline_always_with_dead_code.rs index 2b21dee6c..9dc50dae2 100644 --- a/tests/run-coverage/auxiliary/inline_always_with_dead_code.rs +++ b/tests/run-coverage/auxiliary/inline_always_with_dead_code.rs @@ -4,9 +4,9 @@ mod foo { #[inline(always)] - pub fn called() { } + pub fn called() {} - fn uncalled() { } + fn uncalled() {} } pub mod bar { diff --git a/tests/run-coverage/auxiliary/macro_name_span_helper.rs b/tests/run-coverage/auxiliary/macro_name_span_helper.rs new file mode 100644 index 000000000..6797c081d --- /dev/null +++ b/tests/run-coverage/auxiliary/macro_name_span_helper.rs @@ -0,0 +1,10 @@ +// edition: 2021 + +#[macro_export] +macro_rules! macro_that_defines_a_function { + (fn $name:ident () $body:tt) => { + fn $name () -> () $body + } +} + +// Non-executable comment. diff --git a/tests/run-coverage/auxiliary/unused_mod_helper.rs b/tests/run-coverage/auxiliary/unused_mod_helper.rs index ae1cc1531..88c5dac65 100644 --- a/tests/run-coverage/auxiliary/unused_mod_helper.rs +++ b/tests/run-coverage/auxiliary/unused_mod_helper.rs @@ -1,3 +1,4 @@ +#[allow(dead_code)] pub fn never_called_function() { println!("I am never called"); } diff --git a/tests/run-coverage/auxiliary/used_crate.rs b/tests/run-coverage/auxiliary/used_crate.rs index 16592d48d..c086ef21e 100644 --- a/tests/run-coverage/auxiliary/used_crate.rs +++ b/tests/run-coverage/auxiliary/used_crate.rs @@ -1,6 +1,8 @@ #![allow(unused_assignments, unused_variables)] +// Verify that coverage works with optimizations: // compile-flags: -C opt-level=3 -use std::fmt::Debug; // ^^ validates coverage now works with optimizations + +use std::fmt::Debug; pub fn used_function() { // Initialize test constants in a way that cannot be determined at compile time, to ensure @@ -42,6 +44,7 @@ pub fn unused_function() { } } +#[allow(dead_code)] fn unused_private_function() { let is_true = std::env::args().len() == 1; let mut countdown = 2; diff --git a/tests/run-coverage/auxiliary/used_inline_crate.rs b/tests/run-coverage/auxiliary/used_inline_crate.rs index 8b8e9d548..e8929de6b 100644 --- a/tests/run-coverage/auxiliary/used_inline_crate.rs +++ b/tests/run-coverage/auxiliary/used_inline_crate.rs @@ -1,7 +1,7 @@ #![allow(unused_assignments, unused_variables)] - +// Verify that coverage works with optimizations: // compile-flags: -C opt-level=3 -// ^^ validates coverage now works with optimizations + use std::fmt::Debug; pub fn used_function() { @@ -29,12 +29,6 @@ pub fn used_inline_function() { use_this_lib_crate(); } - - - - - - #[inline(always)] pub fn used_only_from_bin_crate_generic_function<T: Debug>(arg: T) { println!("used_only_from_bin_crate_generic_function with {:?}", arg); @@ -71,6 +65,7 @@ pub fn unused_function() { } #[inline(always)] +#[allow(dead_code)] fn unused_private_function() { let is_true = std::env::args().len() == 1; let mut countdown = 2; diff --git a/tests/run-coverage/closure.coverage b/tests/run-coverage/closure.coverage index 809cf1f48..67014f792 100644 --- a/tests/run-coverage/closure.coverage +++ b/tests/run-coverage/closure.coverage @@ -1,11 +1,16 @@ LL| |#![allow(unused_assignments, unused_variables)] LL| |// compile-flags: -C opt-level=2 - LL| 1|fn main() { // ^^ fix described in rustc_middle/mir/mono.rs + LL| | + LL| |// This test used to be sensitive to certain coverage-specific hacks in + LL| |// `rustc_middle/mir/mono.rs`, but those hacks were later cleaned up by + LL| |// <https://github.com/rust-lang/rust/pull/83666>. + LL| | + LL| 1|fn main() { LL| 1| // Initialize test constants in a way that cannot be determined at compile time, to ensure LL| 1| // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from LL| 1| // dependent conditions. LL| 1| let is_true = std::env::args().len() == 1; - LL| 1| let is_false = ! is_true; + LL| 1| let is_false = !is_true; LL| 1| LL| 1| let mut some_string = Some(String::from("the string content")); LL| 1| println!( @@ -71,8 +76,8 @@ LL| 1| some_string = None; LL| 1| let LL| 1| a - LL| 1| = - LL| 1| || + LL| | = + LL| | || LL| 1| { LL| 1| let mut countdown = 0; LL| 1| if is_false { @@ -93,8 +98,8 @@ LL| 1| LL| 1| let LL| 1| quote_closure - LL| 1| = - LL| 1| |val| + LL| | = + LL| | |val| LL| 5| { LL| 5| let mut countdown = 0; LL| 5| if is_false { @@ -181,7 +186,7 @@ LL| | ; LL| | LL| 1| let short_used_not_covered_closure_line_break_block_embedded_branch = - LL| 1| | _unused_arg: u8 | + LL| | | _unused_arg: u8 | LL| 0| { LL| 0| println!( LL| 0| "not called: {}", @@ -191,7 +196,7 @@ LL| | ; LL| | LL| 1| let short_used_covered_closure_line_break_no_block_embedded_branch = - LL| 1| | _unused_arg: u8 | + LL| | | _unused_arg: u8 | LL| 1| println!( LL| 1| "not called: {}", LL| 1| if is_true { "check" } else { "me" } @@ -200,7 +205,7 @@ LL| | ; LL| | LL| 1| let short_used_covered_closure_line_break_block_embedded_branch = - LL| 1| | _unused_arg: u8 | + LL| | | _unused_arg: u8 | LL| 1| { LL| 1| println!( LL| 1| "not called: {}", diff --git a/tests/run-coverage/closure.rs b/tests/run-coverage/closure.rs index eb3a1ebff..16a2c4e33 100644 --- a/tests/run-coverage/closure.rs +++ b/tests/run-coverage/closure.rs @@ -1,11 +1,16 @@ #![allow(unused_assignments, unused_variables)] // compile-flags: -C opt-level=2 -fn main() { // ^^ fix described in rustc_middle/mir/mono.rs + +// This test used to be sensitive to certain coverage-specific hacks in +// `rustc_middle/mir/mono.rs`, but those hacks were later cleaned up by +// <https://github.com/rust-lang/rust/pull/83666>. + +fn main() { // Initialize test constants in a way that cannot be determined at compile time, to ensure // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from // dependent conditions. let is_true = std::env::args().len() == 1; - let is_false = ! is_true; + let is_false = !is_true; let mut some_string = Some(String::from("the string content")); println!( diff --git a/tests/run-coverage/closure_bug.coverage b/tests/run-coverage/closure_bug.coverage new file mode 100644 index 000000000..f3299834b --- /dev/null +++ b/tests/run-coverage/closure_bug.coverage @@ -0,0 +1,53 @@ + LL| |// Regression test for #115930. + LL| |// All of these closures are identical, and should produce identical output in + LL| |// the coverage report. However, an unstable sort was causing them to be treated + LL| |// inconsistently when preparing coverage spans. + LL| | + LL| 1|fn main() { + LL| 1| let truthy = std::env::args().len() == 1; + LL| 1| + LL| 1| let a + LL| | = + LL| | | + LL| | | + LL| 2| if truthy { true } else { false }; + ^0 + LL| | + LL| 1| a(); + LL| 1| if truthy { a(); } + ^0 + LL| | + LL| 1| let b + LL| | = + LL| | | + LL| | | + LL| 2| if truthy { true } else { false }; + ^0 + LL| | + LL| 1| b(); + LL| 1| if truthy { b(); } + ^0 + LL| | + LL| 1| let c + LL| | = + LL| | | + LL| | | + LL| 2| if truthy { true } else { false }; + ^0 + LL| | + LL| 1| c(); + LL| 1| if truthy { c(); } + ^0 + LL| | + LL| 1| let d + LL| | = + LL| | | + LL| | | + LL| 2| if truthy { true } else { false }; + ^0 + LL| | + LL| 1| d(); + LL| 1| if truthy { d(); } + ^0 + LL| 1|} + diff --git a/tests/run-coverage/closure_bug.rs b/tests/run-coverage/closure_bug.rs new file mode 100644 index 000000000..739bc5f0b --- /dev/null +++ b/tests/run-coverage/closure_bug.rs @@ -0,0 +1,44 @@ +// Regression test for #115930. +// All of these closures are identical, and should produce identical output in +// the coverage report. However, an unstable sort was causing them to be treated +// inconsistently when preparing coverage spans. + +fn main() { + let truthy = std::env::args().len() == 1; + + let a + = + | + | + if truthy { true } else { false }; + + a(); + if truthy { a(); } + + let b + = + | + | + if truthy { true } else { false }; + + b(); + if truthy { b(); } + + let c + = + | + | + if truthy { true } else { false }; + + c(); + if truthy { c(); } + + let d + = + | + | + if truthy { true } else { false }; + + d(); + if truthy { d(); } +} diff --git a/tests/run-coverage/closure_macro.coverage b/tests/run-coverage/closure_macro.coverage index 1bfd2013d..0f2c917e0 100644 --- a/tests/run-coverage/closure_macro.coverage +++ b/tests/run-coverage/closure_macro.coverage @@ -1,5 +1,5 @@ LL| |// compile-flags: --edition=2018 - LL| |#![feature(no_coverage)] + LL| |#![feature(coverage_attribute)] LL| | LL| |macro_rules! bail { LL| | ($msg:literal $(,)?) => { diff --git a/tests/run-coverage/closure_macro.rs b/tests/run-coverage/closure_macro.rs index 5e3b00d1e..9b289141c 100644 --- a/tests/run-coverage/closure_macro.rs +++ b/tests/run-coverage/closure_macro.rs @@ -1,5 +1,5 @@ // compile-flags: --edition=2018 -#![feature(no_coverage)] +#![feature(coverage_attribute)] macro_rules! bail { ($msg:literal $(,)?) => { diff --git a/tests/run-coverage/closure_macro_async.coverage b/tests/run-coverage/closure_macro_async.coverage index 0e4365fc7..74247f1bc 100644 --- a/tests/run-coverage/closure_macro_async.coverage +++ b/tests/run-coverage/closure_macro_async.coverage @@ -1,5 +1,5 @@ LL| |// compile-flags: --edition=2018 - LL| |#![feature(no_coverage)] + LL| |#![feature(coverage_attribute)] LL| | LL| |macro_rules! bail { LL| | ($msg:literal $(,)?) => { @@ -40,9 +40,9 @@ LL| 1| Ok(()) LL| 1|} LL| | - LL| |#[no_coverage] + LL| |#[coverage(off)] LL| |fn main() { - LL| | executor::block_on(test()); + LL| | executor::block_on(test()).unwrap(); LL| |} LL| | LL| |mod executor { @@ -52,22 +52,18 @@ LL| | task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, LL| | }; LL| | - LL| | #[no_coverage] + LL| | #[coverage(off)] LL| | pub fn block_on<F: Future>(mut future: F) -> F::Output { LL| | let mut future = unsafe { Pin::new_unchecked(&mut future) }; LL| | use std::hint::unreachable_unchecked; LL| | static VTABLE: RawWakerVTable = RawWakerVTable::new( - LL| | - LL| | #[no_coverage] + LL| | #[coverage(off)] LL| | |_| unsafe { unreachable_unchecked() }, // clone - LL| | - LL| | #[no_coverage] + LL| | #[coverage(off)] LL| | |_| unsafe { unreachable_unchecked() }, // wake - LL| | - LL| | #[no_coverage] + LL| | #[coverage(off)] LL| | |_| unsafe { unreachable_unchecked() }, // wake_by_ref - LL| | - LL| | #[no_coverage] + LL| | #[coverage(off)] LL| | |_| (), LL| | ); LL| | let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) }; diff --git a/tests/run-coverage/closure_macro_async.rs b/tests/run-coverage/closure_macro_async.rs index e3e89e9c8..b4275599e 100644 --- a/tests/run-coverage/closure_macro_async.rs +++ b/tests/run-coverage/closure_macro_async.rs @@ -1,5 +1,5 @@ // compile-flags: --edition=2018 -#![feature(no_coverage)] +#![feature(coverage_attribute)] macro_rules! bail { ($msg:literal $(,)?) => { @@ -39,9 +39,9 @@ pub async fn test() -> Result<(), String> { Ok(()) } -#[no_coverage] +#[coverage(off)] fn main() { - executor::block_on(test()); + executor::block_on(test()).unwrap(); } mod executor { @@ -51,22 +51,18 @@ mod executor { task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, }; - #[no_coverage] + #[coverage(off)] pub fn block_on<F: Future>(mut future: F) -> F::Output { let mut future = unsafe { Pin::new_unchecked(&mut future) }; use std::hint::unreachable_unchecked; static VTABLE: RawWakerVTable = RawWakerVTable::new( - - #[no_coverage] + #[coverage(off)] |_| unsafe { unreachable_unchecked() }, // clone - - #[no_coverage] + #[coverage(off)] |_| unsafe { unreachable_unchecked() }, // wake - - #[no_coverage] + #[coverage(off)] |_| unsafe { unreachable_unchecked() }, // wake_by_ref - - #[no_coverage] + #[coverage(off)] |_| (), ); let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) }; diff --git a/tests/run-coverage/conditions.coverage b/tests/run-coverage/conditions.coverage index 4749c353a..473335ff6 100644 --- a/tests/run-coverage/conditions.coverage +++ b/tests/run-coverage/conditions.coverage @@ -59,7 +59,6 @@ LL| | } LL| 0| } LL| | - LL| | LL| 1| let mut countdown = 0; LL| 1| if true { LL| 1| countdown = 1; diff --git a/tests/run-coverage/conditions.rs b/tests/run-coverage/conditions.rs index 057599d1b..fa7f2a116 100644 --- a/tests/run-coverage/conditions.rs +++ b/tests/run-coverage/conditions.rs @@ -55,7 +55,6 @@ fn main() { } } - let mut countdown = 0; if true { countdown = 1; diff --git a/tests/run-coverage/dead_code.coverage b/tests/run-coverage/dead_code.coverage index 5074d8b3c..c4ee9f23f 100644 --- a/tests/run-coverage/dead_code.coverage +++ b/tests/run-coverage/dead_code.coverage @@ -1,4 +1,4 @@ - LL| |#![allow(unused_assignments, unused_variables)] + LL| |#![allow(dead_code, unused_assignments, unused_variables)] LL| | LL| 0|pub fn unused_pub_fn_not_in_library() { LL| 0| // Initialize test constants in a way that cannot be determined at compile time, to ensure diff --git a/tests/run-coverage/dead_code.rs b/tests/run-coverage/dead_code.rs index a1285df0e..3492712a6 100644 --- a/tests/run-coverage/dead_code.rs +++ b/tests/run-coverage/dead_code.rs @@ -1,4 +1,4 @@ -#![allow(unused_assignments, unused_variables)] +#![allow(dead_code, unused_assignments, unused_variables)] pub fn unused_pub_fn_not_in_library() { // Initialize test constants in a way that cannot be determined at compile time, to ensure diff --git a/tests/run-coverage/drop_trait.coverage b/tests/run-coverage/drop_trait.coverage index c99b980a3..2c9439a93 100644 --- a/tests/run-coverage/drop_trait.coverage +++ b/tests/run-coverage/drop_trait.coverage @@ -11,7 +11,7 @@ LL| 2| } LL| |} LL| | - LL| 1|fn main() -> Result<(),u8> { + LL| 1|fn main() -> Result<(), u8> { LL| 1| let _firecracker = Firework { strength: 1 }; LL| 1| LL| 1| let _tnt = Firework { strength: 100 }; diff --git a/tests/run-coverage/drop_trait.rs b/tests/run-coverage/drop_trait.rs index a9b5d1d1e..7b062719c 100644 --- a/tests/run-coverage/drop_trait.rs +++ b/tests/run-coverage/drop_trait.rs @@ -11,7 +11,7 @@ impl Drop for Firework { } } -fn main() -> Result<(),u8> { +fn main() -> Result<(), u8> { let _firecracker = Firework { strength: 1 }; let _tnt = Firework { strength: 100 }; diff --git a/tests/run-coverage/generics.coverage b/tests/run-coverage/generics.coverage index 2ff8f917e..098391835 100644 --- a/tests/run-coverage/generics.coverage +++ b/tests/run-coverage/generics.coverage @@ -41,7 +41,7 @@ ------------------ LL| |} LL| | - LL| 1|fn main() -> Result<(),u8> { + LL| 1|fn main() -> Result<(), u8> { LL| 1| let mut firecracker = Firework { strength: 1 }; LL| 1| firecracker.set_strength(2); LL| 1| @@ -54,10 +54,6 @@ LL| 1| return Err(1); LL| 0| } LL| 0| - LL| 0| - LL| 0| - LL| 0| - LL| 0| LL| 0| let _ = Firework { strength: 1000 }; LL| 0| LL| 0| Ok(()) diff --git a/tests/run-coverage/generics.rs b/tests/run-coverage/generics.rs index 150ffb9db..bf4c2d8d6 100644 --- a/tests/run-coverage/generics.rs +++ b/tests/run-coverage/generics.rs @@ -19,7 +19,7 @@ impl<T> Drop for Firework<T> where T: Copy + std::fmt::Display { } } -fn main() -> Result<(),u8> { +fn main() -> Result<(), u8> { let mut firecracker = Firework { strength: 1 }; firecracker.set_strength(2); @@ -32,10 +32,6 @@ fn main() -> Result<(),u8> { return Err(1); } - - - - let _ = Firework { strength: 1000 }; Ok(()) diff --git a/tests/run-coverage/issue-85461.coverage b/tests/run-coverage/issue-85461.coverage index f97ab2303..cbc910664 100644 --- a/tests/run-coverage/issue-85461.coverage +++ b/tests/run-coverage/issue-85461.coverage @@ -5,9 +5,9 @@ $DIR/auxiliary/inline_always_with_dead_code.rs: LL| | LL| |mod foo { LL| | #[inline(always)] - LL| 2| pub fn called() { } + LL| 2| pub fn called() {} LL| | - LL| 0| fn uncalled() { } + LL| 0| fn uncalled() {} LL| |} LL| | LL| |pub mod bar { @@ -24,6 +24,7 @@ $DIR/auxiliary/inline_always_with_dead_code.rs: $DIR/issue-85461.rs: LL| |// Regression test for #85461: MSVC sometimes fail to link with dead code and #[inline(always)] + LL| | LL| |// aux-build:inline_always_with_dead_code.rs LL| |extern crate inline_always_with_dead_code; LL| | diff --git a/tests/run-coverage/issue-85461.rs b/tests/run-coverage/issue-85461.rs index 6f626b4a6..9d4c90a82 100644 --- a/tests/run-coverage/issue-85461.rs +++ b/tests/run-coverage/issue-85461.rs @@ -1,4 +1,5 @@ // Regression test for #85461: MSVC sometimes fail to link with dead code and #[inline(always)] + // aux-build:inline_always_with_dead_code.rs extern crate inline_always_with_dead_code; diff --git a/tests/run-coverage/issue-93054.coverage b/tests/run-coverage/issue-93054.coverage index 074e6b983..15f225326 100644 --- a/tests/run-coverage/issue-93054.coverage +++ b/tests/run-coverage/issue-93054.coverage @@ -1,29 +1,31 @@ + LL| |#![allow(dead_code, unreachable_code)] + LL| | LL| |// Regression test for #93054: Functions using uninhabited types often only have a single, LL| |// unreachable basic block which doesn't get instrumented. This should not cause llvm-cov to fail. LL| |// Since these kinds functions can't be invoked anyway, it's ok to not have coverage data for them. LL| | LL| |// compile-flags: --edition=2021 LL| | - LL| |enum Never { } + LL| |enum Never {} LL| | LL| |impl Never { LL| | fn foo(self) { - LL| | match self { } - LL| | make().map(|never| match never { }); + LL| | match self {} + LL| | make().map(|never| match never {}); LL| | } LL| | LL| | fn bar(&self) { - LL| | match *self { } + LL| | match *self {} LL| | } LL| |} LL| | LL| 0|async fn foo2(never: Never) { - LL| | match never { } + LL| | match never {} LL| |} LL| | LL| 0|fn make() -> Option<Never> { LL| 0| None LL| 0|} LL| | - LL| 1|fn main() { } + LL| 1|fn main() {} diff --git a/tests/run-coverage/issue-93054.rs b/tests/run-coverage/issue-93054.rs index c160b3db0..da546cfee 100644 --- a/tests/run-coverage/issue-93054.rs +++ b/tests/run-coverage/issue-93054.rs @@ -1,28 +1,30 @@ +#![allow(dead_code, unreachable_code)] + // Regression test for #93054: Functions using uninhabited types often only have a single, // unreachable basic block which doesn't get instrumented. This should not cause llvm-cov to fail. // Since these kinds functions can't be invoked anyway, it's ok to not have coverage data for them. // compile-flags: --edition=2021 -enum Never { } +enum Never {} impl Never { fn foo(self) { - match self { } - make().map(|never| match never { }); + match self {} + make().map(|never| match never {}); } fn bar(&self) { - match *self { } + match *self {} } } async fn foo2(never: Never) { - match never { } + match never {} } fn make() -> Option<Never> { None } -fn main() { } +fn main() {} diff --git a/tests/run-coverage/lazy_boolean.coverage b/tests/run-coverage/lazy_boolean.coverage index 2d927a083..8f14082ef 100644 --- a/tests/run-coverage/lazy_boolean.coverage +++ b/tests/run-coverage/lazy_boolean.coverage @@ -32,7 +32,7 @@ ^0 LL| | LL| | if - LL| 1| ! + LL| | ! LL| 1| is_true LL| 0| { LL| 0| a = 2 diff --git a/tests/run-coverage/loops_branches.coverage b/tests/run-coverage/loops_branches.coverage index 148a22377..8cd6f1be3 100644 --- a/tests/run-coverage/loops_branches.coverage +++ b/tests/run-coverage/loops_branches.coverage @@ -9,8 +9,7 @@ LL| 1| fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { LL| 1| if true { LL| 1| if false { - LL| 0| while true { - LL| 0| } + LL| 0| while true {} LL| 1| } LL| 1| write!(f, "cool")?; ^0 diff --git a/tests/run-coverage/loops_branches.rs b/tests/run-coverage/loops_branches.rs index 7116ce47f..f3a343bcc 100644 --- a/tests/run-coverage/loops_branches.rs +++ b/tests/run-coverage/loops_branches.rs @@ -9,8 +9,7 @@ impl std::fmt::Debug for DebugTest { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { if true { if false { - while true { - } + while true {} } write!(f, "cool")?; } else { diff --git a/tests/run-coverage/macro_name_span.coverage b/tests/run-coverage/macro_name_span.coverage new file mode 100644 index 000000000..cadf70246 --- /dev/null +++ b/tests/run-coverage/macro_name_span.coverage @@ -0,0 +1,39 @@ +$DIR/auxiliary/macro_name_span_helper.rs: + LL| |// edition: 2021 + LL| | + LL| |#[macro_export] + LL| |macro_rules! macro_that_defines_a_function { + LL| | (fn $name:ident () $body:tt) => { + LL| 1| fn $name () -> () $body + LL| | } + LL| |} + LL| | + LL| |// Non-executable comment. + +$DIR/macro_name_span.rs: + LL| |// edition: 2021 + LL| | + LL| |// Regression test for <https://github.com/rust-lang/rust/issues/117788>. + LL| |// Under some circumstances, the heuristics that detect macro name spans can + LL| |// get confused and produce incorrect spans beyond the bounds of the span + LL| |// being processed. + LL| | + LL| |// aux-build: macro_name_span_helper.rs + LL| |extern crate macro_name_span_helper; + LL| | + LL| 1|fn main() { + LL| 1| affected_function(); + LL| 1|} + LL| | + LL| |macro_rules! macro_with_an_unreasonably_and_egregiously_long_name { + LL| | () => { + LL| | println!("hello"); + LL| | }; + LL| |} + LL| | + LL| |macro_name_span_helper::macro_that_defines_a_function! { + LL| | fn affected_function() { + LL| | macro_with_an_unreasonably_and_egregiously_long_name!(); + LL| | } + LL| |} + diff --git a/tests/run-coverage/macro_name_span.rs b/tests/run-coverage/macro_name_span.rs new file mode 100644 index 000000000..5d15977c4 --- /dev/null +++ b/tests/run-coverage/macro_name_span.rs @@ -0,0 +1,25 @@ +// edition: 2021 + +// Regression test for <https://github.com/rust-lang/rust/issues/117788>. +// Under some circumstances, the heuristics that detect macro name spans can +// get confused and produce incorrect spans beyond the bounds of the span +// being processed. + +// aux-build: macro_name_span_helper.rs +extern crate macro_name_span_helper; + +fn main() { + affected_function(); +} + +macro_rules! macro_with_an_unreasonably_and_egregiously_long_name { + () => { + println!("hello"); + }; +} + +macro_name_span_helper::macro_that_defines_a_function! { + fn affected_function() { + macro_with_an_unreasonably_and_egregiously_long_name!(); + } +} diff --git a/tests/run-coverage/match_or_pattern.coverage b/tests/run-coverage/match_or_pattern.coverage index 0b5a2c03d..94c796721 100644 --- a/tests/run-coverage/match_or_pattern.coverage +++ b/tests/run-coverage/match_or_pattern.coverage @@ -1,5 +1,3 @@ - LL| |#![feature(or_patterns)] - LL| | LL| 1|fn main() { LL| 1| // Initialize test constants in a way that cannot be determined at compile time, to ensure LL| 1| // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from diff --git a/tests/run-coverage/match_or_pattern.rs b/tests/run-coverage/match_or_pattern.rs index 4c6a8a9b7..ab7aee51d 100644 --- a/tests/run-coverage/match_or_pattern.rs +++ b/tests/run-coverage/match_or_pattern.rs @@ -1,5 +1,3 @@ -#![feature(or_patterns)] - fn main() { // Initialize test constants in a way that cannot be determined at compile time, to ensure // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from diff --git a/tests/run-coverage/no_cov_crate.coverage b/tests/run-coverage/no_cov_crate.coverage index c34dbde88..f5a0322bf 100644 --- a/tests/run-coverage/no_cov_crate.coverage +++ b/tests/run-coverage/no_cov_crate.coverage @@ -1,17 +1,18 @@ - LL| |// Enables `no_coverage` on the entire crate - LL| |#![feature(no_coverage)] + LL| |// Enables `coverage(off)` on the entire crate + LL| |#![feature(coverage_attribute)] LL| | - LL| |#[no_coverage] + LL| |#[coverage(off)] LL| |fn do_not_add_coverage_1() { LL| | println!("called but not covered"); LL| |} LL| | LL| |fn do_not_add_coverage_2() { - LL| | #![no_coverage] + LL| | #![coverage(off)] LL| | println!("called but not covered"); LL| |} LL| | - LL| |#[no_coverage] + LL| |#[coverage(off)] + LL| |#[allow(dead_code)] LL| |fn do_not_add_coverage_not_called() { LL| | println!("not called and not covered"); LL| |} @@ -24,6 +25,7 @@ LL| 1| println!("called and covered"); LL| 1|} LL| | + LL| |#[allow(dead_code)] LL| 0|fn add_coverage_not_called() { LL| 0| println!("not called but covered"); LL| 0|} @@ -31,7 +33,7 @@ LL| |// FIXME: These test-cases illustrate confusing results of nested functions. LL| |// See https://github.com/rust-lang/rust/issues/93319 LL| |mod nested_fns { - LL| | #[no_coverage] + LL| | #[coverage(off)] LL| | pub fn outer_not_covered(is_true: bool) { LL| 1| fn inner(is_true: bool) { LL| 1| if is_true { @@ -48,7 +50,7 @@ LL| 1| println!("called and covered"); LL| 1| inner_not_covered(is_true); LL| 1| - LL| 1| #[no_coverage] + LL| 1| #[coverage(off)] LL| 1| fn inner_not_covered(is_true: bool) { LL| 1| if is_true { LL| 1| println!("called but not covered"); diff --git a/tests/run-coverage/no_cov_crate.rs b/tests/run-coverage/no_cov_crate.rs index 0bfbdda2c..e12e4bc55 100644 --- a/tests/run-coverage/no_cov_crate.rs +++ b/tests/run-coverage/no_cov_crate.rs @@ -1,17 +1,18 @@ -// Enables `no_coverage` on the entire crate -#![feature(no_coverage)] +// Enables `coverage(off)` on the entire crate +#![feature(coverage_attribute)] -#[no_coverage] +#[coverage(off)] fn do_not_add_coverage_1() { println!("called but not covered"); } fn do_not_add_coverage_2() { - #![no_coverage] + #![coverage(off)] println!("called but not covered"); } -#[no_coverage] +#[coverage(off)] +#[allow(dead_code)] fn do_not_add_coverage_not_called() { println!("not called and not covered"); } @@ -24,6 +25,7 @@ fn add_coverage_2() { println!("called and covered"); } +#[allow(dead_code)] fn add_coverage_not_called() { println!("not called but covered"); } @@ -31,7 +33,7 @@ fn add_coverage_not_called() { // FIXME: These test-cases illustrate confusing results of nested functions. // See https://github.com/rust-lang/rust/issues/93319 mod nested_fns { - #[no_coverage] + #[coverage(off)] pub fn outer_not_covered(is_true: bool) { fn inner(is_true: bool) { if is_true { @@ -48,7 +50,7 @@ mod nested_fns { println!("called and covered"); inner_not_covered(is_true); - #[no_coverage] + #[coverage(off)] fn inner_not_covered(is_true: bool) { if is_true { println!("called but not covered"); diff --git a/tests/run-coverage/overflow.coverage b/tests/run-coverage/overflow.coverage index 2d60316e2..cee076e88 100644 --- a/tests/run-coverage/overflow.coverage +++ b/tests/run-coverage/overflow.coverage @@ -12,7 +12,7 @@ LL| 4| result LL| 4|} LL| | - LL| 1|fn main() -> Result<(),u8> { + LL| 1|fn main() -> Result<(), u8> { LL| 1| let mut countdown = 10; LL| 11| while countdown > 0 { LL| 11| if countdown == 1 { diff --git a/tests/run-coverage/overflow.rs b/tests/run-coverage/overflow.rs index 7df8de6f3..bbb65c1b3 100644 --- a/tests/run-coverage/overflow.rs +++ b/tests/run-coverage/overflow.rs @@ -12,7 +12,7 @@ fn might_overflow(to_add: u32) -> u32 { result } -fn main() -> Result<(),u8> { +fn main() -> Result<(), u8> { let mut countdown = 10; while countdown > 0 { if countdown == 1 { diff --git a/tests/run-coverage/try_error_result.coverage b/tests/run-coverage/try_error_result.coverage index fcdb7437d..5d48cbd62 100644 --- a/tests/run-coverage/try_error_result.coverage +++ b/tests/run-coverage/try_error_result.coverage @@ -1,7 +1,7 @@ LL| |#![allow(unused_assignments)] LL| |// failure-status: 1 LL| | - LL| 6|fn call(return_error: bool) -> Result<(),()> { + LL| 6|fn call(return_error: bool) -> Result<(), ()> { LL| 6| if return_error { LL| 1| Err(()) LL| | } else { @@ -9,7 +9,7 @@ LL| | } LL| 6|} LL| | - LL| 1|fn test1() -> Result<(),()> { + LL| 1|fn test1() -> Result<(), ()> { LL| 1| let mut LL| 1| countdown = 10 LL| | ; @@ -38,18 +38,18 @@ LL| | LL| |struct Thing1; LL| |impl Thing1 { - LL| 18| fn get_thing_2(&self, return_error: bool) -> Result<Thing2,()> { + LL| 18| fn get_thing_2(&self, return_error: bool) -> Result<Thing2, ()> { LL| 18| if return_error { LL| 1| Err(()) LL| | } else { - LL| 17| Ok(Thing2{}) + LL| 17| Ok(Thing2 {}) LL| | } LL| 18| } LL| |} LL| | LL| |struct Thing2; LL| |impl Thing2 { - LL| 17| fn call(&self, return_error: bool) -> Result<u32,()> { + LL| 17| fn call(&self, return_error: bool) -> Result<u32, ()> { LL| 17| if return_error { LL| 2| Err(()) LL| | } else { @@ -58,7 +58,7 @@ LL| 17| } LL| |} LL| | - LL| 1|fn test2() -> Result<(),()> { + LL| 1|fn test2() -> Result<(), ()> { LL| 1| let thing1 = Thing1{}; LL| 1| let mut LL| 1| countdown = 10 @@ -115,7 +115,7 @@ LL| 0| Ok(()) LL| 1|} LL| | - LL| 1|fn main() -> Result<(),()> { + LL| 1|fn main() -> Result<(), ()> { LL| 1| test1().expect_err("test1 should fail"); LL| 1| test2() LL| 1| ? diff --git a/tests/run-coverage/try_error_result.rs b/tests/run-coverage/try_error_result.rs index 9eb1d2db2..557cbf22b 100644 --- a/tests/run-coverage/try_error_result.rs +++ b/tests/run-coverage/try_error_result.rs @@ -1,7 +1,7 @@ #![allow(unused_assignments)] // failure-status: 1 -fn call(return_error: bool) -> Result<(),()> { +fn call(return_error: bool) -> Result<(), ()> { if return_error { Err(()) } else { @@ -9,7 +9,7 @@ fn call(return_error: bool) -> Result<(),()> { } } -fn test1() -> Result<(),()> { +fn test1() -> Result<(), ()> { let mut countdown = 10 ; @@ -37,18 +37,18 @@ fn test1() -> Result<(),()> { struct Thing1; impl Thing1 { - fn get_thing_2(&self, return_error: bool) -> Result<Thing2,()> { + fn get_thing_2(&self, return_error: bool) -> Result<Thing2, ()> { if return_error { Err(()) } else { - Ok(Thing2{}) + Ok(Thing2 {}) } } } struct Thing2; impl Thing2 { - fn call(&self, return_error: bool) -> Result<u32,()> { + fn call(&self, return_error: bool) -> Result<u32, ()> { if return_error { Err(()) } else { @@ -57,7 +57,7 @@ impl Thing2 { } } -fn test2() -> Result<(),()> { +fn test2() -> Result<(), ()> { let thing1 = Thing1{}; let mut countdown = 10 @@ -109,7 +109,7 @@ fn test2() -> Result<(),()> { Ok(()) } -fn main() -> Result<(),()> { +fn main() -> Result<(), ()> { test1().expect_err("test1 should fail"); test2() ? diff --git a/tests/run-coverage/unused.coverage b/tests/run-coverage/unused.coverage index ba25e34bf..056ffeb02 100644 --- a/tests/run-coverage/unused.coverage +++ b/tests/run-coverage/unused.coverage @@ -1,3 +1,5 @@ + LL| |#![allow(dead_code, unused_assignments, unused_must_use, unused_variables)] + LL| | LL| 2|fn foo<T>(x: T) { LL| 2| let mut i = 0; LL| 22| while i < 10 { diff --git a/tests/run-coverage/unused.rs b/tests/run-coverage/unused.rs index fb6113eb0..d985af135 100644 --- a/tests/run-coverage/unused.rs +++ b/tests/run-coverage/unused.rs @@ -1,3 +1,5 @@ +#![allow(dead_code, unused_assignments, unused_must_use, unused_variables)] + fn foo<T>(x: T) { let mut i = 0; while i < 10 { diff --git a/tests/run-coverage/unused_mod.coverage b/tests/run-coverage/unused_mod.coverage index 558dfaa5c..a8fa24ac6 100644 --- a/tests/run-coverage/unused_mod.coverage +++ b/tests/run-coverage/unused_mod.coverage @@ -1,4 +1,5 @@ $DIR/auxiliary/unused_mod_helper.rs: + LL| |#[allow(dead_code)] LL| 0|pub fn never_called_function() { LL| 0| println!("I am never called"); LL| 0|} diff --git a/tests/run-coverage/uses_crate.coverage b/tests/run-coverage/uses_crate.coverage index 9da096dbd..50d92102a 100644 --- a/tests/run-coverage/uses_crate.coverage +++ b/tests/run-coverage/uses_crate.coverage @@ -1,7 +1,9 @@ $DIR/auxiliary/used_crate.rs: LL| |#![allow(unused_assignments, unused_variables)] + LL| |// Verify that coverage works with optimizations: LL| |// compile-flags: -C opt-level=3 - LL| |use std::fmt::Debug; // ^^ validates coverage now works with optimizations + LL| | + LL| |use std::fmt::Debug; LL| | LL| 1|pub fn used_function() { LL| 1| // Initialize test constants in a way that cannot be determined at compile time, to ensure @@ -90,6 +92,7 @@ $DIR/auxiliary/used_crate.rs: LL| 0| } LL| 0|} LL| | + LL| |#[allow(dead_code)] LL| 0|fn unused_private_function() { LL| 0| let is_true = std::env::args().len() == 1; LL| 0| let mut countdown = 2; diff --git a/tests/run-coverage/uses_inline_crate.coverage b/tests/run-coverage/uses_inline_crate.coverage index 48493e207..cc0e01ffd 100644 --- a/tests/run-coverage/uses_inline_crate.coverage +++ b/tests/run-coverage/uses_inline_crate.coverage @@ -1,8 +1,8 @@ $DIR/auxiliary/used_inline_crate.rs: LL| |#![allow(unused_assignments, unused_variables)] - LL| | + LL| |// Verify that coverage works with optimizations: LL| |// compile-flags: -C opt-level=3 - LL| |// ^^ validates coverage now works with optimizations + LL| | LL| |use std::fmt::Debug; LL| | LL| 1|pub fn used_function() { @@ -32,12 +32,6 @@ $DIR/auxiliary/used_inline_crate.rs: LL| 1| use_this_lib_crate(); LL| 1|} LL| | - LL| | - LL| | - LL| | - LL| | - LL| | - LL| | LL| |#[inline(always)] LL| 2|pub fn used_only_from_bin_crate_generic_function<T: Debug>(arg: T) { LL| 2| println!("used_only_from_bin_crate_generic_function with {:?}", arg); @@ -120,6 +114,7 @@ $DIR/auxiliary/used_inline_crate.rs: LL| 0|} LL| | LL| |#[inline(always)] + LL| |#[allow(dead_code)] LL| 0|fn unused_private_function() { LL| 0| let is_true = std::env::args().len() == 1; LL| 0| let mut countdown = 2; diff --git a/tests/run-coverage/while_early_ret.coverage b/tests/run-coverage/while_early_ret.coverage index 97808447a..49d39d366 100644 --- a/tests/run-coverage/while_early_ret.coverage +++ b/tests/run-coverage/while_early_ret.coverage @@ -1,7 +1,7 @@ LL| |#![allow(unused_assignments)] LL| |// failure-status: 1 LL| | - LL| 1|fn main() -> Result<(),u8> { + LL| 1|fn main() -> Result<(), u8> { LL| 1| let mut countdown = 10; LL| | while LL| 7| countdown diff --git a/tests/run-coverage/while_early_ret.rs b/tests/run-coverage/while_early_ret.rs index 1c83c8fc7..b2f0eee2c 100644 --- a/tests/run-coverage/while_early_ret.rs +++ b/tests/run-coverage/while_early_ret.rs @@ -1,7 +1,7 @@ #![allow(unused_assignments)] // failure-status: 1 -fn main() -> Result<(),u8> { +fn main() -> Result<(), u8> { let mut countdown = 10; while countdown diff --git a/tests/run-coverage/yield.coverage b/tests/run-coverage/yield.coverage index 383dd9915..90c2641a7 100644 --- a/tests/run-coverage/yield.coverage +++ b/tests/run-coverage/yield.coverage @@ -7,7 +7,7 @@ LL| 1|fn main() { LL| 1| let mut generator = || { LL| 1| yield 1; - LL| 1| return "foo" + LL| 1| return "foo"; LL| 1| }; LL| | LL| 1| match Pin::new(&mut generator).resume(()) { @@ -23,7 +23,7 @@ LL| 1| yield 1; LL| 1| yield 2; LL| 0| yield 3; - LL| 0| return "foo" + LL| 0| return "foo"; LL| 0| }; LL| | LL| 1| match Pin::new(&mut generator).resume(()) { diff --git a/tests/run-coverage/yield.rs b/tests/run-coverage/yield.rs index ff7616656..361275c92 100644 --- a/tests/run-coverage/yield.rs +++ b/tests/run-coverage/yield.rs @@ -7,7 +7,7 @@ use std::pin::Pin; fn main() { let mut generator = || { yield 1; - return "foo" + return "foo"; }; match Pin::new(&mut generator).resume(()) { @@ -23,7 +23,7 @@ fn main() { yield 1; yield 2; yield 3; - return "foo" + return "foo"; }; match Pin::new(&mut generator).resume(()) { |