fix(settings): mark drop guard as !Send #695
Merged
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.
Fixes #694
Because the
SettingsDropGuard
modifies aThreadLocalKey
(it clones it in theSettings::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'sCURRENT_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 withasync
code, as when held acrossawait
points is can be moved by the runtime to a separate thread.We fix it by adding a
PhantomData
field toSettingsDropGuard
that does not implementSend
. We verify it works by adding acompile_fail
doctest to the struct that tries to send the drop guard to a different thread.