diff options
| author | Zalathar <Zalathar@users.noreply.github.com> | 2025-07-29 10:29:32 +1000 |
|---|---|---|
| committer | Zalathar <Zalathar@users.noreply.github.com> | 2025-07-29 11:36:43 +1000 |
| commit | 7ca4d1f6a155e802b31cfc1f0971f3916aa8e02d (patch) | |
| tree | 25b249c19d65744537e4f3186edda5948cd7aaa7 /tests/coverage/auxiliary/try_in_macro_helper.rs | |
| parent | 498ae9fed2e7d90821d70a048f3770f91af08957 (diff) | |
| download | rust-7ca4d1f6a155e802b31cfc1f0971f3916aa8e02d.tar.gz rust-7ca4d1f6a155e802b31cfc1f0971f3916aa8e02d.zip | |
coverage: Regression test for "function name is empty" bug
The bug was triggered by a particular usage of the `?` try operator in a proc-macro expansion. Thanks to lqd for the minimization. Co-authored-by: Rémy Rakic <remy.rakic+github@gmail.com>
Diffstat (limited to 'tests/coverage/auxiliary/try_in_macro_helper.rs')
| -rw-r--r-- | tests/coverage/auxiliary/try_in_macro_helper.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/coverage/auxiliary/try_in_macro_helper.rs b/tests/coverage/auxiliary/try_in_macro_helper.rs new file mode 100644 index 00000000000..27d2af15b05 --- /dev/null +++ b/tests/coverage/auxiliary/try_in_macro_helper.rs @@ -0,0 +1,31 @@ +//@ edition: 2024 +// (The proc-macro crate doesn't need to be instrumented.) +//@ compile-flags: -Cinstrument-coverage=off + +use proc_macro::TokenStream; + +/// Minimized form of `#[derive(arbitrary::Arbitrary)]` that still triggers +/// the original bug. +const CODE: &str = " + impl Arbitrary for MyEnum { + fn try_size_hint() -> Option<usize> { + Some(0)?; + None + } + } +"; + +#[proc_macro_attribute] +pub fn attr(_attr: TokenStream, _item: TokenStream) -> TokenStream { + CODE.parse().unwrap() +} + +#[proc_macro] +pub fn bang(_item: TokenStream) -> TokenStream { + CODE.parse().unwrap() +} + +#[proc_macro_derive(Arbitrary)] +pub fn derive_arbitrary(_item: TokenStream) -> TokenStream { + CODE.parse().unwrap() +} |
