Skip to content

Commit

Permalink
Add E0766 error for unterminated double quote byte string
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jun 25, 2020
1 parent 67100f6 commit eb6d9a4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/librustc_error_codes/error_codes.rs
Expand Up @@ -446,6 +446,7 @@ 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"),
E0766: include_str!("./error_codes/E0766.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/E0766.md
@@ -0,0 +1,13 @@
A double quote byte string (`b"`) was not terminated.

Erroneous code example:

```compile_fail,E0766
let s = b"; // error!
```

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

```
let s = b""; // ok!
```
15 changes: 9 additions & 6 deletions src/librustc_parse/lexer/mod.rs
Expand Up @@ -367,12 +367,15 @@ impl<'a> StringReader<'a> {
}
rustc_lexer::LiteralKind::ByteStr { terminated } => {
if !terminated {
self.fatal_span_(
start + BytePos(1),
suffix_start,
"unterminated double quote byte string",
)
.raise()
self.sess
.span_diagnostic
.struct_span_fatal_with_code(
self.mk_sp(start + BytePos(1), suffix_start),
"unterminated double quote byte string",
error_code!(E0766),
)
.emit();
FatalError.raise();
}
(token::ByteStr, Mode::ByteStr, 2, 1) // b" "
}
Expand Down

0 comments on commit eb6d9a4

Please sign in to comment.