mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-30 03:57:37 +00:00

Lexing precedes parsing, as you'd expect: `Lexer` creates a `TokenStream` and `Parser` then parses that `TokenStream`. But, in a horrendous violation of layering abstractions and common sense, `Lexer` depends on `Parser`! The `Lexer::unclosed_delim_err` method does some error recovery that relies on creating a `Parser` to do some post-processing of the `TokenStream` that the `Lexer` just created. This commit just removes `unclosed_delim_err`. This change removes `Lexer`'s dependency on `Parser`, and also means that `lex_token_tree`'s return value can have a more typical form. The cost is slightly worse error messages in two obscure cases, as shown in these tests: - tests/ui/parser/brace-in-let-chain.rs: there is slightly less explanation in this case involving an extra `{`. - tests/ui/parser/diff-markers/unclosed-delims{,-in-macro}.rs: the diff marker detection is no longer supported (because that detection is implemented in the parser). In my opinion this cost is outweighed by the magnitude of the code cleanup.
13 lines
312 B
Rust
13 lines
312 B
Rust
// The diff marker detection was removed for this example, because it relied on
|
|
// the lexer having a dependency on the parser, which was horrible.
|
|
|
|
mod tests {
|
|
#[test]
|
|
<<<<<<< HEAD
|
|
fn test1() {
|
|
=======
|
|
fn test2() {
|
|
>>>>>>> 7a4f13c blah blah blah
|
|
}
|
|
} //~ this file contains an unclosed delimiter
|