]> git.lizzy.rs Git - rust.git/commitdiff
Create new error code E0762 for unterminated char literals
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Wed, 10 Jun 2020 09:53:57 +0000 (11:53 +0200)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Wed, 10 Jun 2020 09:54:09 +0000 (11:54 +0200)
src/librustc_error_codes/error_codes.rs
src/librustc_error_codes/error_codes/E0762.md [new file with mode: 0644]
src/librustc_parse/lexer/mod.rs

index ec5b3251e6883b250e00a8cc094ba756ddac1568..285242647b38d5dd770998f52396758135e22a57 100644 (file)
 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
diff --git a/src/librustc_error_codes/error_codes/E0762.md b/src/librustc_error_codes/error_codes/E0762.md
new file mode 100644 (file)
index 0000000..b01ded4
--- /dev/null
@@ -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!
+```
index 9bc6a50acad048ab375ac890c2557ddcb82ede1d..d135f713478a0fadabded00e0f5333c187214908 100644 (file)
@@ -325,7 +325,15 @@ fn cook_lexer_literal(
         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) // ' '
             }