Skip to content

Commit

Permalink
Rollup merge of rust-lang#73280 - GuillaumeGomez:add-e0763, r=petroch…
Browse files Browse the repository at this point in the history
…enkov

Add E0763
  • Loading branch information
Dylan-DPC committed Jun 17, 2020
2 parents 6fbaa35 + bad252c commit 211537c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 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 @@ -443,6 +443,7 @@ E0759: include_str!("./error_codes/E0759.md"),
E0760: include_str!("./error_codes/E0760.md"),
E0761: include_str!("./error_codes/E0761.md"),
E0762: include_str!("./error_codes/E0762.md"),
E0763: include_str!("./error_codes/E0763.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/E0763.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
A byte constant wasn't correctly ended.

Erroneous code example:

```compile_fail,E0763
let c = b'a; // error!
```

To fix this error, add the missing quote:

```
let c = b'a'; // ok!
```
11 changes: 9 additions & 2 deletions src/librustc_parse/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,15 @@ impl<'a> StringReader<'a> {
}
rustc_lexer::LiteralKind::Byte { terminated } => {
if !terminated {
self.fatal_span_(start + BytePos(1), suffix_start, "unterminated byte constant")
.raise()
self.sess
.span_diagnostic
.struct_span_fatal_with_code(
self.mk_sp(start + BytePos(1), suffix_start),
"unterminated byte constant",
error_code!(E0763),
)
.emit();
FatalError.raise();
}
(token::Byte, Mode::Byte, 2, 1) // b' '
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/byte-literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ pub fn main() {
b' '; //~ ERROR byte constant must be escaped
b'''; //~ ERROR byte constant must be escaped
b'é'; //~ ERROR byte constant must be ASCII
b'a //~ ERROR unterminated byte constant
b'a //~ ERROR unterminated byte constant [E0763]
}
3 changes: 2 additions & 1 deletion src/test/ui/parser/byte-literals.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ error: byte constant must be ASCII. Use a \xHH escape for a non-ASCII byte
LL | b'é';
| ^

error: unterminated byte constant
error[E0763]: unterminated byte constant
--> $DIR/byte-literals.rs:11:6
|
LL | b'a
| ^^^^

error: aborting due to 7 previous errors

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

0 comments on commit 211537c

Please sign in to comment.