rust-lang / reference

The Rust Reference
https://doc.rust-lang.org/nightly/reference/
Apache License 2.0
1.16k stars 451 forks source link

Lexer: say that lifetime-like tokens can't be immediately followed by ' #1479

Closed mattheww closed 2 months ago

mattheww commented 2 months ago

Forms like 'ab'c are rejected, so we need some way to explain why they don't tokenise as two consecutive LIFETIME_OR_LABEL tokens.

I think the best way to do this, given the Reference's current approach, is simply to add "not immediately followed by '" to the lexer rules for the lifetime-like tokens.

That matches what the implementation (lifetime_or_char()) is doing, so it's not likely to be wrong, and this chapter already has some cases of lookahead of this sort.

It also means there can be no ambiguity between CHAR_LITERAL and these tokens (I think the intent is that we have a traditional "longest matching token wins" rule, which would give the right result here, but that isn't explicitly stated anywhere).