Skip to content

Conversation

@HiteshMittal07
Copy link
Contributor

Summary

Adds a compile-time warning when no #[test_fuzz] attributes are found in an impl block.

Why?

Previously, missing test_fuzz attributes failed silently. This warning helps users notice the issue early without breaking compilation.

Related Issue
Fixes #676

@CLAassistant
Copy link

CLAassistant commented Jan 27, 2026

CLA assistant check
All committers have signed the CLA.

@smoelius
Copy link
Collaborator

The reasons for the failures are not your PR. I will fix them and then get back to you.

Copy link
Collaborator

@smoelius smoelius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for doing this.

If you rebase onto the new master, I think the errors will go away.

macro/src/lib.rs Outdated
});

let (impl_items, modules) = map_impl_items(&generics, trait_path.as_ref(), &self_ty, &items);
let warning = if modules.is_empty() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking modules.is_empty() is clever!

But rather than add code with a deprecated attribute, I think you can just eprintln! a warning. You might model after this:

"Warning: Command failed for target {}: {:?}\nstdout: ```\n{}\n```",

Would it be a huge imposition to add a test to verify that the warning is emitted?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HiteshMittal07 Did you use a deprecated attribute because you knew it would point to the location of the test_fuzz_impl attribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smoelius Actually, the intention was to emit a compiler-level warning, since the issue title was "test_fuzz_impl should warn when no test_fuzz attributes are found."

@HiteshMittal07 HiteshMittal07 force-pushed the improvement/test-fuzz-attribute-check branch from e4fcc4c to 2b8e069 Compare January 28, 2026 07:33
macro/src/lib.rs Outdated

let (impl_items, modules) = map_impl_items(&generics, trait_path.as_ref(), &self_ty, &items);
if modules.is_empty() {
eprintln!("warning: no `test_fuzz` attributes found in this `impl` block");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
eprintln!("warning: no `test_fuzz` attributes found in this `impl` block");
eprintln!("Warning: No `test_fuzz` attributes found in `impl` block");

Capitalizing "Warning' and "No" is for consistency with existing warnings. Removing "this" is because, when I see it in the logs, it is unclear what "this" refers to: https://github.com/trailofbits/test-fuzz/actions/runs/21429362910/job/61705010100?pr=685#step:15:16

Ideally, the warning would include information about where the test_fuzz_impl attribute occurs in the source code, but that could be a separate, future change.

If you could, please apply this suggestion and then squash your commits down to one. Then I will merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smoelius I’ve applied the suggestion and squashed my commits into one. From my side, it’s ready to merge. Please let me know if there are any further suggestions.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

use testing::{CommandExt, fuzzable};

#[test]
fn warning() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 Wonderfully concise!

@HiteshMittal07 HiteshMittal07 force-pushed the improvement/test-fuzz-attribute-check branch from 151b004 to 8ae9f47 Compare January 28, 2026 11:37
Replace deprecated-based warning with stderr warning

Add test for missing test_fuzz warning
@HiteshMittal07 HiteshMittal07 force-pushed the improvement/test-fuzz-attribute-check branch from 8ae9f47 to 7237b68 Compare January 28, 2026 11:55
@smoelius smoelius added this pull request to the merge queue Jan 28, 2026
Merged via the queue into trailofbits:master with commit cca7099 Jan 28, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_fuzz_impl should warn when no test_fuzz attributes are found

3 participants