Skip to content

Commit

Permalink
Rollup merge of rust-lang#73581 - GuillaumeGomez:add-0766, r=varkor
Browse files Browse the repository at this point in the history
Create 0766 error code
  • Loading branch information
Manishearth authored Jun 26, 2020
2 parents 0aef6ff + 33302fa commit 3fc8f8e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 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 @@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
3 changes: 2 additions & 1 deletion src/test/ui/parser/byte-string-literals.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ error: byte constant must be ASCII. Use a \xHH escape for a non-ASCII byte
LL | b"é";
| ^

error: unterminated double quote byte string
error[E0766]: unterminated double quote byte string
--> $DIR/byte-string-literals.rs:7:6
|
LL | b"a
Expand All @@ -32,3 +32,4 @@ LL | | }

error: aborting due to 5 previous errors

For more information about this error, try `rustc --explain E0766`.

0 comments on commit 3fc8f8e

Please sign in to comment.