Skip to content

Commit d2f7d6b

Browse files
authored
Rollup merge of rust-lang#73581 - GuillaumeGomez:add-0766, r=varkor
Create 0766 error code
2 parents 59768d4 + 33302fa commit d2f7d6b

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

src/librustc_error_codes/error_codes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ E0762: include_str!("./error_codes/E0762.md"),
446446
E0763: include_str!("./error_codes/E0763.md"),
447447
E0764: include_str!("./error_codes/E0764.md"),
448448
E0765: include_str!("./error_codes/E0765.md"),
449+
E0766: include_str!("./error_codes/E0766.md"),
449450
;
450451
// E0006, // merged with E0005
451452
// E0008, // cannot bind by-move into a pattern guard
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
A double quote byte string (`b"`) was not terminated.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0766
6+
let s = b"; // error!
7+
```
8+
9+
To fix this error, add the missing double quote at the end of the string:
10+
11+
```
12+
let s = b""; // ok!
13+
```

src/librustc_parse/lexer/mod.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,15 @@ impl<'a> StringReader<'a> {
367367
}
368368
rustc_lexer::LiteralKind::ByteStr { terminated } => {
369369
if !terminated {
370-
self.fatal_span_(
371-
start + BytePos(1),
372-
suffix_start,
373-
"unterminated double quote byte string",
374-
)
375-
.raise()
370+
self.sess
371+
.span_diagnostic
372+
.struct_span_fatal_with_code(
373+
self.mk_sp(start + BytePos(1), suffix_start),
374+
"unterminated double quote byte string",
375+
error_code!(E0766),
376+
)
377+
.emit();
378+
FatalError.raise();
376379
}
377380
(token::ByteStr, Mode::ByteStr, 2, 1) // b" "
378381
}

src/test/ui/parser/byte-string-literals.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ error: byte constant must be ASCII. Use a \xHH escape for a non-ASCII byte
2222
LL | b"é";
2323
| ^
2424

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

3333
error: aborting due to 5 previous errors
3434

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

0 commit comments

Comments
 (0)