forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#134192 - nnethercote:rm-Lexer-Parser-dep, r=compiler-errors Remove `Lexer`'s dependency on `Parser`. 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. r? ```````@chenyukang```````
- Loading branch information
Showing
8 changed files
with
68 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
// The diff marker detection was removed for this example, because it relied on | ||
// the lexer having a dependency on the parser, which was horrible. | ||
|
||
macro_rules! foo { | ||
<<<<<<< HEAD | ||
//~^ ERROR encountered diff marker | ||
() { | ||
======= | ||
() { // | ||
>>>>>>> 7a4f13c blah blah blah | ||
} | ||
} | ||
} //~ this file contains an unclosed delimiter |
27 changes: 10 additions & 17 deletions
27
tests/ui/parser/diff-markers/unclosed-delims-in-macro.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,16 @@ | ||
error: encountered diff marker | ||
--> $DIR/unclosed-delims-in-macro.rs:2:1 | ||
error: this file contains an unclosed delimiter | ||
--> $DIR/unclosed-delims-in-macro.rs:11:48 | ||
| | ||
LL | macro_rules! foo { | ||
| - unclosed delimiter | ||
LL | <<<<<<< HEAD | ||
| ^^^^^^^ between this marker and `=======` is the code that we're merging into | ||
LL | () { | ||
| - this delimiter might not be properly closed... | ||
... | ||
LL | ======= | ||
| ------- between this marker and `>>>>>>>` is the incoming code | ||
LL | () { // | ||
LL | >>>>>>> 7a4f13c blah blah blah | ||
| ^^^^^^^ this marker concludes the conflict region | ||
| | ||
= note: conflict markers indicate that a merge was started but could not be completed due to merge conflicts | ||
to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers | ||
= help: if you're having merge conflicts after pulling new code: | ||
the top section is the code you already had and the bottom section is the remote code | ||
if you're in the middle of a rebase: | ||
the top section is the code being rebased onto and the bottom section is the code coming from the current commit being rebased | ||
= note: for an explanation on these markers from the `git` documentation: | ||
visit <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts> | ||
LL | } | ||
| - ^ | ||
| | | ||
| ...as it matches this but it has different indentation | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,12 @@ | ||
// 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 | ||
//~^ ERROR encountered diff marker | ||
//~| NOTE between this marker and `=======` | ||
|
||
//~| NOTE conflict markers indicate that | ||
//~| HELP if you're having merge conflicts | ||
//~| NOTE for an explanation on these markers | ||
|
||
fn test1() { | ||
======= | ||
//~^ NOTE between this marker and `>>>>>>>` | ||
fn test2() { | ||
>>>>>>> 7a4f13c blah blah blah | ||
//~^ NOTE this marker concludes the conflict region | ||
} | ||
} | ||
} //~ this file contains an unclosed delimiter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,16 @@ | ||
error: encountered diff marker | ||
--> $DIR/unclosed-delims.rs:3:1 | ||
error: this file contains an unclosed delimiter | ||
--> $DIR/unclosed-delims.rs:12:48 | ||
| | ||
LL | <<<<<<< HEAD | ||
| ^^^^^^^ between this marker and `=======` is the code that we're merging into | ||
LL | mod tests { | ||
| - unclosed delimiter | ||
... | ||
LL | ======= | ||
| ------- between this marker and `>>>>>>>` is the incoming code | ||
LL | fn test1() { | ||
| - this delimiter might not be properly closed... | ||
... | ||
LL | >>>>>>> 7a4f13c blah blah blah | ||
| ^^^^^^^ this marker concludes the conflict region | ||
| | ||
= note: conflict markers indicate that a merge was started but could not be completed due to merge conflicts | ||
to resolve a conflict, keep only the code you want and then delete the lines containing conflict markers | ||
= help: if you're having merge conflicts after pulling new code: | ||
the top section is the code you already had and the bottom section is the remote code | ||
if you're in the middle of a rebase: | ||
the top section is the code being rebased onto and the bottom section is the code coming from the current commit being rebased | ||
= note: for an explanation on these markers from the `git` documentation: | ||
visit <https://git-scm.com/book/en/v2/Git-Tools-Advanced-Merging#_checking_out_conflicts> | ||
LL | } | ||
| - ^ | ||
| | | ||
| ...as it matches this but it has different indentation | ||
|
||
error: aborting due to 1 previous error | ||
|