Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 43dbdbc

Browse files
authoredJun 11, 2020
Rollup merge of rust-lang#73164 - GuillaumeGomez:add-e0761, r=petrochenkov
Add new E0762 error code
2 parents 2d8ef1c + 7bd87cf commit 43dbdbc

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed
 

‎src/librustc_error_codes/error_codes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ E0754: include_str!("./error_codes/E0754.md"),
440440
E0758: include_str!("./error_codes/E0758.md"),
441441
E0760: include_str!("./error_codes/E0760.md"),
442442
E0761: include_str!("./error_codes/E0761.md"),
443+
E0762: include_str!("./error_codes/E0762.md"),
443444
;
444445
// E0006, // merged with E0005
445446
// E0008, // cannot bind by-move into a pattern guard
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
A character literal wasn't ended with a quote.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0762
6+
static C: char = '●; // error!
7+
```
8+
9+
To fix this error, add the missing quote:
10+
11+
```
12+
static C: char = '●'; // ok!
13+
```

‎src/librustc_parse/lexer/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,15 @@ impl<'a> StringReader<'a> {
325325
let (lit_kind, mode, prefix_len, postfix_len) = match kind {
326326
rustc_lexer::LiteralKind::Char { terminated } => {
327327
if !terminated {
328-
self.fatal_span_(start, suffix_start, "unterminated character literal").raise()
328+
self.sess
329+
.span_diagnostic
330+
.struct_span_fatal_with_code(
331+
self.mk_sp(start, suffix_start),
332+
"unterminated character literal",
333+
error_code!(E0762),
334+
)
335+
.emit();
336+
FatalError.raise();
329337
}
330338
(token::Char, Mode::Char, 1, 1) // ' '
331339
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
error: unterminated character literal
1+
error[E0762]: unterminated character literal
22
--> $DIR/lex-bad-char-literals-4.rs:4:5
33
|
44
LL | '●
55
| ^^^^
66

77
error: aborting due to previous error
88

9+
For more information about this error, try `rustc --explain E0762`.

‎src/test/ui/parser/lex-bad-char-literals-7.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ error: empty unicode escape (must have at least 1 hex digit)
1010
LL | let _: char = '\u{}';
1111
| ^^^^
1212

13-
error: unterminated character literal
13+
error[E0762]: unterminated character literal
1414
--> $DIR/lex-bad-char-literals-7.rs:11:13
1515
|
1616
LL | let _ = ' hello // here's a comment
1717
| ^^^^^^^^
1818

1919
error: aborting due to 3 previous errors
2020

21+
For more information about this error, try `rustc --explain E0762`.

0 commit comments

Comments
 (0)
Please sign in to comment.