Skip to content

add SpannedString, a String that remembers its span - #232

Merged
sunshowers merged 1 commit into
jj-stack/parsewrapper-and-tokenstreamwrapper-don-t-work-with-internal-buffering-nznpslrrfrom
jj-stack/add-spannedstring-a-string-that-remembers-its-span-wotyuqpn
Sep 4, 2026
Merged

add SpannedString, a String that remembers its span#232
sunshowers merged 1 commit into
jj-stack/parsewrapper-and-tokenstreamwrapper-don-t-work-with-internal-buffering-nznpslrrfrom
jj-stack/add-spannedstring-a-string-that-remembers-its-span-wotyuqpn

Conversation

@sunshowers

@sunshowers sunshowers commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

In some situations it is useful to carry around span information along with a bare String. There isn't really a syn type that accepts either a LitStr or an Ident the way String does. Introduce SpannedString, which acts as that type and can be used as ParseWrapper<SpannedString>.

One alternative to this is to implement Deserialize on SpannedString directly, but error handling for that would require a third side-channel thread local on top of the two we already have. This is much more straightforward implementation-wise. (It also has a pleasing crispness and orthogonality.)

@sunshowers
sunshowers force-pushed the jj-stack/add-spannedstring-a-string-that-remembers-its-span-wotyuqpn branch from 4147f4f to 831c294 Compare September 2, 2026 09:01

@ahl ahl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really nice

In some situations it is useful to carry around span information along with a bare `String`. There isn't really a syn type that accepts either a `LitStr` or an `Ident` the way `String` does. Introduce `SpannedString`, which acts as that type and can be used as `ParseWrapper<SpannedString>`.

One alternative to this is to implement `Deserialize` on `SpannedString` directly, but error handling for that would require a third side-channel thread local on top of the two we already have. This is much more straightforward implementation-wise. (It also has a pleasing cripness -- it's easier to explain.)
@sunshowers

Copy link
Copy Markdown
Contributor Author

Revision history

Version Changes from previous version Submitted commit
3 (current) 831c294f..60ac74b5 60ac74b5
2 4147f4f9..831c294f 831c294f
1 Initial version 4147f4f9

Generated by jj-stack from this pull request's force-push history.

@sunshowers
sunshowers force-pushed the jj-stack/add-spannedstring-a-string-that-remembers-its-span-wotyuqpn branch from 831c294 to 60ac74b Compare September 4, 2026 20:51
@sunshowers
sunshowers merged commit 18e10d8 into main Sep 4, 2026
8 checks passed
@sunshowers
sunshowers deleted the jj-stack/add-spannedstring-a-string-that-remembers-its-span-wotyuqpn branch September 4, 2026 20:54
Comment thread Cargo.toml
quote = "1.0"
serde = { version = "1.0", features = ["derive"] }
syn = { version = "3.0.2", features = ["full"] }
syn = { version = "3.0.5", features = ["full"] }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumped this up to pull in dtolnay/syn#2080.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants