Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(settings): mark drop guard as !Send (#695)
Fixes #694 Because the `SettingsDropGuard` modifies a `ThreadLocalKey` (it clones it in the `Settings::bind_to_scope` method, then restores it in its drop impl), it should not be moved to a different thread, as then it would modify that thread's `CURRENT_SETTINGS` instead of the original thread's. This is not an issue with normal code as the guard is usually unnameable (`let _guard = settings.bind_to_scope();`). but it is a problem with `async` code, as when held across `await` points is can be moved by the runtime to a separate thread. We fix it by adding a `PhantomData` field to `SettingsDropGuard` that does not implement `Send`. We verify it works by adding a `compile_fail` doctest to the struct that tries to send the drop guard to a different thread.
- Loading branch information