about summary refs log tree commit diff
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2020-06-25 18:00:14 -0700
committerGitHub <noreply@github.com>2020-06-25 18:00:14 -0700
commit0d03456163c308c8c856d1c4d9f2368eed805732 (patch)
tree9d7df0cb87ff80c98d842da770807956a58581e3
parent0d5cfb44ade581cfbeb81163ebba6cad74134c0e (diff)
parent33302fa7d225a2d1152f0fe9a52e55fbd85d3017 (diff)
downloadrust-0d03456163c308c8c856d1c4d9f2368eed805732.tar.gz
rust-0d03456163c308c8c856d1c4d9f2368eed805732.zip
Rollup merge of #73581 - GuillaumeGomez:add-0766, r=varkor
Create 0766 error code
-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
-rw-r--r--src/test/ui/parser/byte-string-literals.stderr3
4 files changed, 25 insertions, 7 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" "
             }
diff --git a/src/test/ui/parser/byte-string-literals.stderr b/src/test/ui/parser/byte-string-literals.stderr
index ca964cd4b8f..9be90644147 100644
--- a/src/test/ui/parser/byte-string-literals.stderr
+++ b/src/test/ui/parser/byte-string-literals.stderr
@@ -22,7 +22,7 @@ error: byte constant must be ASCII. Use a \xHH escape for a non-ASCII byte
 LL |     b"é";
    |       ^
 
-error: unterminated double quote byte string
+error[E0766]: unterminated double quote byte string
   --> $DIR/byte-string-literals.rs:7:6
    |
 LL |       b"a
@@ -32,3 +32,4 @@ LL | | }
 
 error: aborting due to 5 previous errors
 
+For more information about this error, try `rustc --explain E0766`.