Skip to content

feat(codegen): warn when a custom attribute rule matches no generated element - #848

Open
dev-burnern wants to merge 1 commit into
anthropics:mainfrom
dev-burnern:feat/codegen-warn-unmatched-attributes
Open

dev-burnern wants to merge 1 commit into
anthropics:mainfrom
dev-burnern:feat/codegen-warn-unmatched-attributes

Conversation

@dev-burnern

Copy link
Copy Markdown

Closes #697

Summary

generate_with_diagnostics now emits CodeGenWarning::AttributeRuleMatchedNothing { rule, option } for any custom attribute rule in type_attributes, field_attributes, message_attributes, enum_attributes, oneof_attributes, or oneof_struct_field_attributes that matched no generated element during the run.

  • buffa-codegen/src/context.rs:
    • Adds AttributeOption covering all six attribute lists and a RefCell<[Vec<bool>; 6]> match tracker on CodeGenContext.
    • Adds CodeGenContext::matching_attributes_for(option, fqn) (used by all nine call sites across enumeration.rs, message.rs, and oneof.rs) to record matched rules as elements are generated — ensuring exact agreement with what codegen actually emits (extern-mapped types, excluded packages, synthetic proto3-optional oneofs, and wrong-kind paths such as variant paths in oneof_struct_field_attributes all warn automatically).
    • Adds CodeGenContext::warn_unmatched_attributes() called at the end of generate_with_diagnostics().
  • buffa-codegen/src/lib.rs:
    • Adds CodeGenWarning::AttributeRuleMatchedNothing { rule, option } (#[non_exhaustive]) with Display formatting and unit tests covering all six attribute options (both matching rules with 0 warnings and unmatched rules).
  • .changes/unreleased/added-20261122-181800.yaml: adds the changelog fragment.

Verification

  • cargo fmt --check — passed
  • cargo test -p buffa-codegen --lib — 852 passed, 0 failed
  • cargo clippy -p buffa-codegen --all-targets -- -D warnings — passed (0 warnings)
  • RUSTDOCFLAGS="-D warnings" cargo doc -p buffa-codegen --no-deps — passed (0 warnings)

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@dev-burnern

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

This branch has not been deployed

No deployments
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.

codegen: an attribute rule (type_attribute, field_attribute, oneof_struct_field_attribute, …) that matches nothing produces no warning

1 participant