Skip to content

Commit a19dfb5

Browse files
Create new E0763 error code for unterminated byte constant
1 parent 5949391 commit a19dfb5

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

src/librustc_error_codes/error_codes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ E0758: include_str!("./error_codes/E0758.md"),
442442
E0760: include_str!("./error_codes/E0760.md"),
443443
E0761: include_str!("./error_codes/E0761.md"),
444444
E0762: include_str!("./error_codes/E0762.md"),
445+
E0763: include_str!("./error_codes/E0763.md"),
445446
;
446447
// E0006, // merged with E0005
447448
// E0008, // cannot bind by-move into a pattern guard
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
A byte constant wasn't correctly ended.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0763
6+
let c = b'a; // error!
7+
```
8+
9+
To fix this error, add the missing quote:
10+
11+
```
12+
let c = b'a'; // ok!
13+
```

src/librustc_parse/lexer/mod.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,15 @@ impl<'a> StringReader<'a> {
339339
}
340340
rustc_lexer::LiteralKind::Byte { terminated } => {
341341
if !terminated {
342-
self.fatal_span_(start + BytePos(1), suffix_start, "unterminated byte constant")
343-
.raise()
342+
self.sess
343+
.span_diagnostic
344+
.struct_span_fatal_with_code(
345+
self.mk_sp(start + BytePos(1), suffix_start),
346+
"unterminated byte constant",
347+
error_code!(E0763),
348+
)
349+
.emit();
350+
FatalError.raise();
344351
}
345352
(token::Byte, Mode::Byte, 2, 1) // b' '
346353
}

0 commit comments

Comments
 (0)