Create E0765 error for unterminated double quote strings

This commit is contained in:
Guillaume Gomez 2020-06-21 11:24:35 +02:00
parent 228a0ed7b0
commit a657be42b1
3 changed files with 23 additions and 2 deletions

View File

@ -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

View File

@ -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!
```

View File

@ -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) // " "
}