#[builder(with = Some / FromIterator::from_iter / <_>::from_iter)] attribute#157
#[builder(with = Some / FromIterator::from_iter / <_>::from_iter)] attribute#157
#[builder(with = Some / FromIterator::from_iter / <_>::from_iter)] attribute#157Conversation
WalkthroughThe changes in this pull request address multiple error messages related to the usage of builder attributes in Rust code, specifically for Changes
Assessment against linked issues
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI ⛔ Files ignored due to path filters (6)
📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🔇 Additional comments (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
bon/tests/integration/ui/compile_fail/attr_with.stderr (1)
Line range hint
1-61: Consider adding examples for Result usageWhile the error messages are comprehensive, consider enhancing them with a concrete example of correct
Resultusage to complement the existing examples.Example addition to the first error message:
error: expected a closure e.g. `#[builder(with = |param: T| expression)]` or a well-known function path which could be one of: - #[builder(with = Some)] - #[builder(with = FromIterator::from_iter)] - #[builder(with = <_>::from_iter)] (same as above, but shorter) + - #[builder(with = |x: T| -> MyResult<_> { Ok(x) })] (for fallible conversions)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (8)
bon-macros/src/builder/builder_gen/member/config/mod.rsis excluded by!**/*.rsbon-macros/src/builder/builder_gen/member/config/with/closure.rsis excluded by!**/*.rsbon-macros/src/builder/builder_gen/member/config/with/mod.rsis excluded by!**/*.rsbon-macros/src/builder/builder_gen/mod.rsis excluded by!**/*.rsbon-macros/src/builder/builder_gen/setters/mod.rsis excluded by!**/*.rsbon/tests/integration/builder/attr_with/mod.rsis excluded by!**/*.rsbon/tests/integration/builder/attr_with/some.rsis excluded by!**/*.rsbon/tests/integration/ui/compile_fail/attr_transparent.rsis excluded by!**/*.rs
📒 Files selected for processing (3)
- bon/tests/integration/ui/compile_fail/attr_transparent.stderr (1 hunks)
- bon/tests/integration/ui/compile_fail/attr_with.stderr (1 hunks)
- website/changelog.md (1 hunks)
🔇 Additional comments (8)
bon/tests/integration/ui/compile_fail/attr_transparent.stderr (4)
Line range hint
1-24: LGTM! Clear and helpful error messages for transparent attribute.The error messages effectively communicate the constraints for
#[builder(transparent)]:
- Restricted to
Option<T>types- Incompatible with
start_fn,finish_fn, andskipattributes
26-52: LGTM! Helpful error messages with suggestions for method names.The error messages effectively guide users by:
- Clearly indicating which methods don't exist
- Providing helpful suggestions for the correct method names
54-71: LGTM! Comprehensive error message for unset builder member.The error message effectively communicates the build failure by:
- Clearly stating which member is unset
- Explaining the trait implementation requirement
- Providing proper macro context
Line range hint
1-71: Verify error message testing coverage.While the error messages look good, let's ensure we have test coverage for all possible error scenarios with the new builder attribute features.
✅ Verification successful
Error message testing coverage is comprehensive
The test coverage for builder attribute error cases is thorough and well-structured:
attr_transparent.rscovers all invalid combinations:
- Using transparent on required (non-Option) members
- Conflicts with start_fn
- Conflicts with finish_fn
- Conflicts with skip attribute
- Missing setter method errors
Additional error cases are covered in separate compile_fail tests:
attr_with.rsfor with-attribute errorsattr_skip.rsfor skip-attribute errorsattr_top_level_start_finish_fn.rsfor start/finish function errorsThe positive test cases in
builder/attr_transparent.rscomplement these by verifying correct usage scenarios.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Check for comprehensive error message testing echo "Checking for all error test cases..." # Look for other compile_fail tests related to builder attributes fd -e rs . tests/integration/ui/compile_fail/ --exec grep -l "builder.*with.*Some\|builder.*with.*FromIterator\|builder.*transparent" # Look for test cases in the source rg "#\[test\].*builder.*with" tests/Length of output: 426
Script:
#!/bin/bash # Let's first find all compile_fail test files fd -e rs . -t f # Then look for builder-related test files rg -l "derive.*Builder" # And specifically look for transparent attribute tests rg -l "#\[builder.*transparent\]"Length of output: 9393
Script:
#!/bin/bash # Let's examine the test coverage more specifically # Check compile_fail tests for transparent attribute rg -C 5 "transparent" bon/tests/integration/ui/compile_fail/attr_transparent.rs # Check positive test cases for transparent attribute rg -C 5 "transparent" bon/tests/integration/builder/attr_transparent.rs # Look for other builder attribute combinations in compile_fail tests rg -l "builder.*with|builder.*skip|builder.*start_fn|builder.*finish_fn" bon/tests/integration/ui/compile_fail/Length of output: 5773
bon/tests/integration/ui/compile_fail/attr_with.stderr (4)
1-5: Excellent error message improvements for basic usage!The error message now clearly documents the three supported patterns for the
withattribute:
#[builder(with = Some)]#[builder(with = FromIterator::from_iter)]#[builder(with = <_>::from_iter)]This aligns perfectly with the PR objectives and provides clear guidance to users.
Line range hint
11-41: Clear restrictions on attribute combinations and keywordsThe error messages effectively prevent:
- Combining
withandintoattributes- Using
for<...>lifetime syntax- Using restricted keywords (
const,static,async,move)This helps maintain clean and predictable builder patterns.
Line range hint
47-79: Comprehensive guidance for return type annotationsThe error messages provide excellent documentation about return type options:
- No annotation for direct type returns
-> *Result<_, ErrorType>for fallible setters- Support for custom Result types (e.g.,
ApiResult<_>)The messages also clearly explain the underlying type concept with respect to
Option<T>and#[builder(transparent)].
Line range hint
54-61: Type mismatch errors maintain Rust's high standardThe error messages preserve Rust's excellent type error reporting:
- Clear indication of expected vs found types
- Helpful notes about type parameter influence
- Precise source locations for type mismatches
Closes #22.
Although.. the issue above was already closed by #145 where the attribute
#[builder(with)]was introduced. However, this PR adds the convenience shortcut#[builder(with = FromIterator::from_iter)]or#[builder(with = <_>::from_iter)].The part of
#[builder(with = Some)]of this PR closes #35, or more specifically the remaining item described in #35 (comment)Summary by CodeRabbit
New Features
Bug Fixes
Documentation