diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-07-29 16:16:46 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-29 16:16:46 +1000 |
| commit | cac55bdd688f4a1bd84263e603ddb34e7d176b51 (patch) | |
| tree | bf7659c12573dcb77c14ce7309ac2a8a1878c226 /tests/coverage/try-in-macro.rs | |
| parent | 95781464e0114ceb388f4a5d3dece46f4551935a (diff) | |
| parent | 7ca4d1f6a155e802b31cfc1f0971f3916aa8e02d (diff) | |
| download | rust-cac55bdd688f4a1bd84263e603ddb34e7d176b51.tar.gz rust-cac55bdd688f4a1bd84263e603ddb34e7d176b51.zip | |
Rollup merge of #144616 - Zalathar:try-in-macro, r=jieyouxu
coverage: Regression test for "function name is empty" bug Regression test for rust-lang/rust#141577, which was triggered by rust-lang/rust#144298. The bug was triggered by a particular usage of the `?` try operator in a proc-macro expansion. Thanks to lqd for the minimization at https://github.com/rust-lang/rust/pull/144571#issuecomment-3127534223. --- I have manually verified that reverting the relevant follow-up fixes (rust-lang/rust#144480 and rust-lang/rust#144530) causes this test to reproduce the bug: ```sh git revert -m1 8aa3d41b8527f9f78e0f2459b50a6e13aea35144 c462895a6f0b463ff0c1c1db2a3a654d7e5976c7 ``` --- r? compiler
Diffstat (limited to 'tests/coverage/try-in-macro.rs')
| -rw-r--r-- | tests/coverage/try-in-macro.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/coverage/try-in-macro.rs b/tests/coverage/try-in-macro.rs new file mode 100644 index 00000000000..ab9d6675418 --- /dev/null +++ b/tests/coverage/try-in-macro.rs @@ -0,0 +1,43 @@ +//! Regression test for <https://github.com/rust-lang/rust/issues/141577>. +//! +//! The changes in <https://github.com/rust-lang/rust/pull/144298> exposed a +//! latent bug that would sometimes cause the compiler to emit a covfun record +//! for a function, but not emit a corresponding PGO symbol name entry, because +//! the function did not have any physical coverage counters. The `llvm-cov` +//! tool would then fail to resolve the covfun record's function name hash, +//! and exit with the cryptic error: +//! +//! ```text +//! malformed instrumentation profile data: function name is empty +//! ``` +//! +//! The bug was then triggered in the wild by the macro-expansion of +//! `#[derive(arbitrary::Arbitrary)]`. +//! +//! This test uses a minimized form of the `Arbitrary` derive macro that was +//! found to still trigger the original bug. The bug could also be triggered +//! by a bang proc-macro or an attribute proc-macro. + +//@ edition: 2024 +//@ revisions: attr bang derive +//@ proc-macro: try_in_macro_helper.rs + +trait Arbitrary { + fn try_size_hint() -> Option<usize>; +} + +// Expand via an attribute proc-macro. +#[cfg_attr(attr, try_in_macro_helper::attr)] +const _: () = (); + +// Expand via a regular bang-style proc-macro. +#[cfg(bang)] +try_in_macro_helper::bang!(); + +// Expand via a derive proc-macro. +#[cfg_attr(derive, derive(try_in_macro_helper::Arbitrary))] +enum MyEnum {} + +fn main() { + MyEnum::try_size_hint(); +} |
