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

Create 0766 error code #73581

Merged
merged 2 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`.