diff --git a/src/libsyntax/error_codes.rs b/src/libsyntax/error_codes.rs index 941df5ea57087..7cf722299ad96 100644 --- a/src/libsyntax/error_codes.rs +++ b/src/libsyntax/error_codes.rs @@ -518,6 +518,24 @@ undefined number of parameters to a given function (like `printf` in C). The equivalent in Rust would be to use macros directly. "##, +E0744: r##" +A raw string isn't terminated. + +Erroneous code example: + +```compile_fail,E0744 +let dolphins = r##"Dolphins!"#; // error! +``` + +To terminate a raw string, you have to have the same number of `#` at the end +than at the beginning. Example: + +``` +let dolphins = r#"Dolphins!"#; // one `#` at the beginning, one at the end so + // all good! +``` +"##, + ; E0539, // incorrect meta item diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index e2a7ea28b9b59..4bf39d59e5907 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -501,8 +501,10 @@ impl<'a> StringReader<'a> { } fn report_unterminated_raw_string(&self, start: BytePos, n_hashes: usize) -> ! { - let mut err = self.struct_span_fatal( - start, start, + let mut err = struct_span_fatal!( + self.sess.span_diagnostic, + self.mk_sp(start, start), + E0744, "unterminated raw string", ); err.span_label( diff --git a/src/test/ui/parser/raw-byte-string-eof.stderr b/src/test/ui/parser/raw-byte-string-eof.stderr index 65fa89f2a81ac..16a953606306b 100644 --- a/src/test/ui/parser/raw-byte-string-eof.stderr +++ b/src/test/ui/parser/raw-byte-string-eof.stderr @@ -1,4 +1,4 @@ -error: unterminated raw string +error[E0744]: unterminated raw string --> $DIR/raw-byte-string-eof.rs:2:5 | LL | br##"a"#; @@ -8,3 +8,4 @@ LL | br##"a"#; error: aborting due to previous error +For more information about this error, try `rustc --explain E0744`. diff --git a/src/test/ui/parser/raw-str-unterminated.stderr b/src/test/ui/parser/raw-str-unterminated.stderr index 67792eb91e5ca..d3c7cc18b63a0 100644 --- a/src/test/ui/parser/raw-str-unterminated.stderr +++ b/src/test/ui/parser/raw-str-unterminated.stderr @@ -1,4 +1,4 @@ -error: unterminated raw string +error[E0744]: unterminated raw string --> $DIR/raw-str-unterminated.rs:2:5 | LL | r#" string literal goes on @@ -8,3 +8,4 @@ LL | r#" string literal goes on error: aborting due to previous error +For more information about this error, try `rustc --explain E0744`. diff --git a/src/test/ui/parser/raw/raw_string.stderr b/src/test/ui/parser/raw/raw_string.stderr index 5572511881d57..e192d07909e48 100644 --- a/src/test/ui/parser/raw/raw_string.stderr +++ b/src/test/ui/parser/raw/raw_string.stderr @@ -1,4 +1,4 @@ -error: unterminated raw string +error[E0744]: unterminated raw string --> $DIR/raw_string.rs:2:13 | LL | let x = r##"lol"#; @@ -8,3 +8,4 @@ LL | let x = r##"lol"#; error: aborting due to previous error +For more information about this error, try `rustc --explain E0744`.