Skip to content

idea: consult git diff for better diagnostics / syntax errors #48911

Closed
@matthiaskrgr

Description

@matthiaskrgr

Just an idea:

Let's say our code looks like this:

fn main() {
	{
		{
			{
				println!("Hello, world!");
		}
	}
}

The error message is not very helpful here, pointing to lines 1 and 8:

error: this file contains an un-closed delimiter
 --> src/main.rs:8:3
  |
8 | }
  |   ^
  |
help: did you mean to close this delimiter?
 --> src/main.rs:1:11
  |
1 | fn main() {
  |           ^

However, since cargo inits new repos as git repo, maybe we can utilize the repo diff and see which brace was added the last:

 fn main() {
        {
                {
-                       println!("Hello, world!");
+                       {
+                               println!("Hello, world!");
                }
        }
 }

and give a better diagnostic:

error: this file contains an un-closed delimiter
 --> src/main.rs:8:3
  |
8 | }
  |   ^
  |
help: did you mean to close this delimiter?
 --> src/main.rs:4:12
  |
4 |                 {
  |                 ^
```

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions