Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trailing newlines affect spans #86076

Open
FabianWolff opened this issue Jun 6, 2021 · 0 comments
Open

Trailing newlines affect spans #86076

FabianWolff opened this issue Jun 6, 2021 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@FabianWolff
Copy link
Contributor

Trailing newlines affect the locations and spans of error messages. For instance:

echo -n '#[i=i::a' > test.rs

produces (when compiling test.rs with rustc):

error: this file contains an unclosed delimiter
 --> test.rs:1:9
  |
1 | #[i=i::a
  |  -      ^
  |  |
  |  unclosed delimiter

error: expected item after attributes
 --> test.rs:1:1
  |
1 | #[i=i::a
  | ^^^^^^^^

error: aborting due to 2 previous errors

Which is what I would expect. However, the same code with a trailing newline:

echo '#[i=i::a' > test.rs

produces:

error: this file contains an unclosed delimiter
 --> test.rs:1:10
  |
1 | #[i=i::a
  |  -       ^
  |  |
  |  unclosed delimiter

error: expected item after attributes
 --> test.rs:1:1
  |
1 | #[i=i::a
  | ^^^^^^^^^

error: aborting due to 2 previous errors

where the first error message points to nowhere (position test.rs:1:10 does not exist), and the span of the second error message is too wide by one character. This initially confused me quite a bit, because it looks like an invisible character in the source file, or an issue with a multibyte character or something. I think that the trailing newline should either be ignored, or that the error should locate EOF in line 2 (and not 1, after the newline, which is at test.rs:1:9).

@FabianWolff FabianWolff added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 6, 2021
@estebank estebank added the A-parser Area: The parsing of Rust source code to an AST label Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants