Skip to content

Commit

Permalink
Create E0765 error for unterminated double quote strings
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jun 21, 2020
1 parent 228a0ed commit a657be4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/librustc_error_codes/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ E0761: include_str!("./error_codes/E0761.md"),
E0762: include_str!("./error_codes/E0762.md"),
E0763: include_str!("./error_codes/E0763.md"),
E0764: include_str!("./error_codes/E0764.md"),
E0765: include_str!("./error_codes/E0765.md"),
;
// E0006, // merged with E0005
// E0008, // cannot bind by-move into a pattern guard
Expand Down
13 changes: 13 additions & 0 deletions src/librustc_error_codes/error_codes/E0765.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
A double quote string (`"`) was not terminated.

Erroneous code example:

```compile_fail,E0765
let s = "; // error!
```

To fix this error, add the missing double quote at the end of the string:

```
let s = ""; // ok!
```
11 changes: 9 additions & 2 deletions src/librustc_parse/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,15 @@ impl<'a> StringReader<'a> {
}
rustc_lexer::LiteralKind::Str { terminated } => {
if !terminated {
self.fatal_span_(start, suffix_start, "unterminated double quote string")
.raise()
self.sess
.span_diagnostic
.struct_span_fatal_with_code(
self.mk_sp(start, suffix_start),
"unterminated double quote string",
error_code!(E0765),
)
.emit();
FatalError.raise();
}
(token::Str, Mode::Str, 1, 1) // " "
}
Expand Down

0 comments on commit a657be4

Please sign in to comment.