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

Add new E0762 error code #73164

Merged
merged 2 commits into from
Jun 11, 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 @@ -440,6 +440,7 @@ E0754: include_str!("./error_codes/E0754.md"),
E0758: include_str!("./error_codes/E0758.md"),
E0760: include_str!("./error_codes/E0760.md"),
E0761: include_str!("./error_codes/E0761.md"),
E0762: include_str!("./error_codes/E0762.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/E0762.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
A character literal wasn't ended with a quote.

Erroneous code example:

```compile_fail,E0762
static C: char = '●; // error!
```

To fix this error, add the missing quote:

```
static C: char = '●'; // ok!
```
10 changes: 9 additions & 1 deletion src/librustc_parse/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,15 @@ impl<'a> StringReader<'a> {
let (lit_kind, mode, prefix_len, postfix_len) = match kind {
rustc_lexer::LiteralKind::Char { terminated } => {
if !terminated {
self.fatal_span_(start, suffix_start, "unterminated character literal").raise()
self.sess
.span_diagnostic
.struct_span_fatal_with_code(
self.mk_sp(start, suffix_start),
"unterminated character literal",
error_code!(E0762),
)
.emit();
FatalError.raise();
}
(token::Char, Mode::Char, 1, 1) // ' '
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/parser/lex-bad-char-literals-4.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
error: unterminated character literal
error[E0762]: unterminated character literal
--> $DIR/lex-bad-char-literals-4.rs:4:5
|
LL | '●
| ^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0762`.
3 changes: 2 additions & 1 deletion src/test/ui/parser/lex-bad-char-literals-7.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ error: empty unicode escape (must have at least 1 hex digit)
LL | let _: char = '\u{}';
| ^^^^

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

error: aborting due to 3 previous errors

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