Don't use Arc in Settings unnecessarily#873
Merged
max-sixty merged 2 commits intomitsuhiko:masterfrom Feb 4, 2026
Merged
Conversation
`Settings` wrap around a set of configuration fields which are shared between instances, with clone-on-write semantics. (All `Settings` objects share the same inner set of fields. When a field's value changes, the fields are cloned locally.) This commit changes things so that `Settings::new` actually creates a new set of fields. Fields are still shared between thread-local `CURRENT_SETTINGS` instances, with the same clone-on-write semantics. Switching from `Arc` to `Rc` like this makes it feasible to store non-`Send`/`Sync` types in `Settings`, which is desirable per mitsuhiko#872.
495c6dc to
2dfde9f
Compare
2 tasks
max-sixty
added a commit
that referenced
this pull request
Feb 5, 2026
## Summary Follow-up to #873 ("Don't use `Arc` in `Settings` unnecessarily"). - Remove `Send + Sync` bounds from `Redaction::Dynamic` variant - Remove `Send + Sync` bounds from `dynamic_redaction()` function - Remove `Send + Sync` bounds from `Settings::add_dynamic_redaction()` method Since `Settings` are stored in thread-local storage and wrapped in `Rc`, they can never cross thread boundaries. The `Send + Sync` bounds were vestigial from when `Arc` was used for `DEFAULT_SETTINGS`. This relaxes the API to allow non-`Send` closures in dynamic redactions, which is now safe since those closures can never be sent to another thread. ## Test plan - [x] All tests pass with `cargo test --all-features` - [x] No clippy warnings 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <noreply@anthropic.com>
Merged
max-sixty
added a commit
that referenced
this pull request
Mar 27, 2026
## Summary - Bump version to 1.47.0 - Update CHANGELOG ### Changes included in this release - Add `Comparator` trait for customizing how snapshot values are compared. #872 (@dstu) - Sort sequences in `sort_maps` to fix non-deterministic `HashSet` snapshots. #876 - Improve TOML serialization error message for unsupported types. #880 - Remove unnecessary `Send + Sync` bounds from `Redaction`, allowing non-`Send` closures in dynamic redactions. #874 - Don't use `Arc` in `Settings` unnecessarily. #873 (@dstu) - Upgrade `console` to 0.16 and MSRV to 1.66. #885 - Upgrade `toml-edit` to 0.25. #882 (@alexanderkjall) > _This was written by Claude Code on behalf of max-sixty_ Co-authored-by: Claude <noreply@anthropic.com>
|
FYI, this is a breaking change (per cargo semver-checks) (discussion appears to be in #872) |
Collaborator
|
is anyone affected by this? or it's just theoretical? |
|
There's a small break in our tests (cedar-policy/cedar-spec#917). We can work around it, but it's enough to block an automatic update. |
Collaborator
|
ok. if you would like a reversion, happy to make it. sorry for the trouble |
max-sixty
added a commit
to max-sixty/insta
that referenced
this pull request
Mar 30, 2026
The Arc→Rc change (mitsuhiko#873) and Send+Sync removal (mitsuhiko#874) were semver-breaking — they removed auto-trait impls from Settings, Redactions, Redaction, and SettingsBindDropGuard. This broke downstream crates like cedar-policy that depend on Send + Sync. Reverts to Arc and restores Send + Sync bounds on Redaction and dynamic_redaction(). Adds Send + Sync to the Comparator trait (new in 1.47.0) for compatibility. Adds a compile-time assertion to prevent future regressions. TODOs mark these as candidates for Rc in the next breaking change. Co-Authored-By: Claude <noreply@anthropic.com>
max-sixty
added a commit
that referenced
this pull request
Mar 30, 2026
The Arc→Rc change (#873) and Send+Sync removal (#874) were semver-breaking — they removed auto-trait impls from `Settings`, `Redactions`, `Redaction`, and `SettingsBindDropGuard`. This broke downstream crates like [cedar-policy](cedar-policy/cedar-spec#917) that depend on `Send + Sync`. This reverts to `Arc` and restores `Send + Sync` bounds on `Redaction` and `dynamic_redaction()`. Also adds `Send + Sync` to the `Comparator` trait (new in 1.47.0) since `Arc<ActualSettings>` requires it. A compile-time assertion prevents future regressions. TODOs mark the `Arc` usage and `Comparator` bounds as candidates for removal in the next breaking change. Thanks to @john-h-kastner-aws for reporting in #873 (comment). > _This was written by Claude Code on behalf of @max-sixty_ Co-authored-by: Claude <noreply@anthropic.com>
Collaborator
|
@john-h-kastner-aws I have reverted. Sorry again for the trouble |
Collaborator
|
@dstu this makes the comparator slightly heavier. But the backward-compat is important, and seems like folks were relying on it. Hope that's OK. |
Contributor
Author
|
Thanks for the heads-up. This doesn't appear to affect the insta-image crate, so things look good from that end. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Per discussion in #871, it seems better for
Settingsto have anRcinternally instead of anArc. This PR makes that change.This passes
make test check-msrv lint check-minver format-check && cargo run -p cargo-insta -- test.Question for review: it would be simpler, and arguably better, if
Settingsjust had fields instead of an innerRc. This should leave theSettingsinterface as it is, since it uses simple interior mutation (fields would continue to be private with public accessors/mutators).As-is,
Settingshas clone-on-write semantics, extra-cheap cloning (bumping a refcount copying fields), and extremely modest memory savings because newly constructedSettingsobjects share a set of immutable fields. But I'm not sure that the complexity imposed by havingSettingswrap a pointer to an innerActualSettingsis justified. Is there a reason for using this pattern?