Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Lifetime span getter and setter #971

Merged
merged 1 commit into from Mar 5, 2021
Merged

Add Lifetime span getter and setter #971

merged 1 commit into from Mar 5, 2021

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Mar 5, 2021

This matches the span and set_span accessors we provide on all the various Lit variant types.

Lifetimes are ordinarily treated as a single token. Only the proc macro API splits them into ' punctuation and ident. Consequently the span of those two things is normally identical, except in pathological case when manually constructed from within a proc macro with differing spans. Thus, requiring macros to decide whether to write lifetime.apostrophe.span or lifetime.ident.span() for that span makes the code misleading. The new accessors reflect the fact that really there is only one span involved.

For example rustc parsers 'a as the following TokenStream, in which byte range 95..97 covers both characters of the entire 'a token.

TokenStream [
    Punct {
        ch: '\'',
        spacing: Joint,
        span: #0 bytes(95..97),
    },
    Ident {
        ident: "asdf",
        span: #0 bytes(95..97),
    },
]

@dtolnay dtolnay merged commit de1a51d into master Mar 5, 2021
@dtolnay dtolnay deleted the lifetime-span branch March 5, 2021 02:05
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.

None yet

1 participant