ParseWrapper and TokenStreamWrapper can't work with internal buffering - #231
Conversation
`ParseWrapper` and `TokenStreamWrapper` receive their tokens through a side channel that only works while our deserializer is in charge. This doesn't really work with scenarios in which serde performs internal buffering. Any attempt to use these wrappers in such a scenario results in the somewhat unhelpful error message:
invalid type: string "foo", expected TokenStream
Improve this error message to indicate that the macro needs to be fixed.
A different option is to gracefully degrade with internal buffering, but I'd rather put the burden on macro authors to improve their diagnostics.
Note that this error message isn't seen with `#[serde(untagged)]` because it swallows each variant's error. But the underlying principle remains the same.
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.
ParseWrapperandTokenStreamWrapperreceive their tokens through a side channel that only works while our deserializer is in charge. This doesn't really work with scenarios in which serde performs internal buffering -- it callsdeserialize_anyto buffer the value as aContentfirst, and only later hands thatContentto the wrapper'sDeserializeimpl. Ourdeserialize_bytesis never called, so the side channel never fires and the wrapper sees a plain string or number.In general, this can't be fixed. Spans can't be serialized, so they can't be roundtripped through
Content. (We could try doing some kind of after-the-kind fixup but that seems dubious.) The alternative is to gracefully degrade by usingSpan::call_site(), but I'd rather put the burden on macro authors to fix their types instead.Currently, any attempt to use these wrappers in such a scenario results in the somewhat unhelpful error message:
Improve this error message to indicate that the macro needs to be fixed, and document the limitation on both wrappers. This error reaches the user as a spanned diagnostic (rather than a panic) due to the span attribution in the
*Accessimpls done earlier in this series.Note that this error message isn't seen with
#[serde(untagged)]because it swallows each variant's error. But the underlying principle remains the same.