about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2020-06-21 14:07:59 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2020-06-25 13:28:45 +0200
commiteb6d9a49a803ee84c9f9aad7ca5657b4ded76941 (patch)
tree37c048a9d4b8d5f7a8b29ef3420960b969b4e971
parent67100f61e62a86f2bf9e38552ee138e231eddc74 (diff)
downloadrust-eb6d9a49a803ee84c9f9aad7ca5657b4ded76941.tar.gz
rust-eb6d9a49a803ee84c9f9aad7ca5657b4ded76941.zip
Add E0766 error for unterminated double quote byte string
-rw-r--r--src/librustc_error_codes/error_codes.rs1
-rw-r--r--src/librustc_error_codes/error_codes/E0766.md13
-rw-r--r--src/librustc_parse/lexer/mod.rs15
3 files changed, 23 insertions, 6 deletions
diff --git a/src/librustc_error_codes/error_codes.rs b/src/librustc_error_codes/error_codes.rs
index 6a5e23adafa..162585360fb 100644
--- a/src/librustc_error_codes/error_codes.rs
+++ b/src/librustc_error_codes/error_codes.rs
@@ -446,6 +446,7 @@ E0762: include_str!("./error_codes/E0762.md"),
 E0763: include_str!("./error_codes/E0763.md"),
 E0764: include_str!("./error_codes/E0764.md"),
 E0765: include_str!("./error_codes/E0765.md"),
+E0766: include_str!("./error_codes/E0766.md"),
 ;
 //  E0006, // merged with E0005
 //  E0008, // cannot bind by-move into a pattern guard
diff --git a/src/librustc_error_codes/error_codes/E0766.md b/src/librustc_error_codes/error_codes/E0766.md
new file mode 100644
index 00000000000..4e775df2cac
--- /dev/null
+++ b/src/librustc_error_codes/error_codes/E0766.md
@@ -0,0 +1,13 @@
+A double quote byte string (`b"`) was not terminated.
+
+Erroneous code example:
+
+```compile_fail,E0766
+let s = b"; // error!
+```
+
+To fix this error, add the missing double quote at the end of the string:
+
+```
+let s = b""; // ok!
+```
diff --git a/src/librustc_parse/lexer/mod.rs b/src/librustc_parse/lexer/mod.rs
index 8e74c3847bc..5050f03bea9 100644
--- a/src/librustc_parse/lexer/mod.rs
+++ b/src/librustc_parse/lexer/mod.rs
@@ -367,12 +367,15 @@ impl<'a> StringReader<'a> {
             }
             rustc_lexer::LiteralKind::ByteStr { terminated } => {
                 if !terminated {
-                    self.fatal_span_(
-                        start + BytePos(1),
-                        suffix_start,
-                        "unterminated double quote byte string",
-                    )
-                    .raise()
+                    self.sess
+                        .span_diagnostic
+                        .struct_span_fatal_with_code(
+                            self.mk_sp(start + BytePos(1), suffix_start),
+                            "unterminated double quote byte string",
+                            error_code!(E0766),
+                        )
+                        .emit();
+                    FatalError.raise();
                 }
                 (token::ByteStr, Mode::ByteStr, 2, 1) // b" "
             }