mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-04 19:28:29 +00:00

Clean `rustc/parse/src/lexer` to improve maintainability This PR refactors the lexer code to improve maintainability and eliminate code duplication. In the first commit, I improve the error handling: - rename `make_unclosed_delims_error` to more appropriate `make_mismatched_closing_delims_errors` - changes return type from Option<Diag> to `Vec<Diag>` to avoid lengthy vec processing at `lex_token_trees` - use `splice` instead of `extend` to make the logic clearer, since `errs` sounds more generic and better suited as a return value In the second commit, I replace the magic number 5 with UNCLOSED_DELIMITER_SHOW_LIMIT constant. In the third commit, I moves `eof_err` function below parsing logic for better code flow. In the forth one, I extract `calculate_spacing` function to eliminate duplicate spacing logic between `bump` and `bump_minimal` functions. r? compiler