From bae5f3976b21f33d9d15ed7da04d3fb9b1878bdc Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 18 Feb 2020 14:50:27 +0100 Subject: [PATCH 1/4] Add E0747 error code --- src/librustc_error_codes/error_codes.rs | 1 + src/librustc_parse/lexer/mod.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/librustc_error_codes/error_codes.rs b/src/librustc_error_codes/error_codes.rs index 91a7b6c895838..89359bb1bfdff 100644 --- a/src/librustc_error_codes/error_codes.rs +++ b/src/librustc_error_codes/error_codes.rs @@ -418,6 +418,7 @@ E0744: include_str!("./error_codes/E0744.md"), E0745: include_str!("./error_codes/E0745.md"), E0746: include_str!("./error_codes/E0746.md"), E0747: include_str!("./error_codes/E0747.md"), +E0748: include_str!("./error_codes/E0748.md"), ; // E0006, // merged with E0005 // E0008, // cannot bind by-move into a pattern guard diff --git a/src/librustc_parse/lexer/mod.rs b/src/librustc_parse/lexer/mod.rs index 66280638a2d40..face0e679927c 100644 --- a/src/librustc_parse/lexer/mod.rs +++ b/src/librustc_parse/lexer/mod.rs @@ -1,5 +1,5 @@ use rustc_data_structures::sync::Lrc; -use rustc_errors::{DiagnosticBuilder, FatalError}; +use rustc_errors::{error_code, DiagnosticBuilder, FatalError}; use rustc_lexer::unescape; use rustc_lexer::Base; use rustc_session::parse::ParseSess; @@ -495,7 +495,11 @@ impl<'a> StringReader<'a> { } fn report_unterminated_raw_string(&self, start: BytePos, n_hashes: usize) -> ! { - let mut err = self.struct_span_fatal(start, start, "unterminated raw string"); + let mut err = self.sess.span_diagnostic.struct_span_fatal_with_code( + self.mk_sp(start, start), + "unterminated raw string", + error_code!(E0748), + ); err.span_label(self.mk_sp(start, start), "unterminated raw string"); if n_hashes > 0 { From f439de36afa8e70d99557a0563341a9211a14096 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 18 Feb 2020 14:50:40 +0100 Subject: [PATCH 2/4] Add explanation for E0747 --- src/librustc_error_codes/error_codes/E0748.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/librustc_error_codes/error_codes/E0748.md diff --git a/src/librustc_error_codes/error_codes/E0748.md b/src/librustc_error_codes/error_codes/E0748.md new file mode 100644 index 0000000000000..7743c722eee42 --- /dev/null +++ b/src/librustc_error_codes/error_codes/E0748.md @@ -0,0 +1,14 @@ +A raw string isn't correctly terminated because the trailing `#` count doesn't +match its leading `#` count. + +Erroneous code example: + +```compile_fail,E0748 +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! +``` From 8ce9460b7a132fa4075325d2ae4c4b4ecd09ffd0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 18 Feb 2020 14:50:48 +0100 Subject: [PATCH 3/4] Update UI tests --- src/test/ui/parser/raw-byte-string-eof.stderr | 3 ++- src/test/ui/parser/raw-str-unterminated.stderr | 3 ++- src/test/ui/parser/raw/raw_string.stderr | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/test/ui/parser/raw-byte-string-eof.stderr b/src/test/ui/parser/raw-byte-string-eof.stderr index 65fa89f2a81ac..d5f22e2a1a814 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[E0748]: 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 E0748`. diff --git a/src/test/ui/parser/raw-str-unterminated.stderr b/src/test/ui/parser/raw-str-unterminated.stderr index 67792eb91e5ca..077f763f154c5 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[E0748]: 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 E0748`. diff --git a/src/test/ui/parser/raw/raw_string.stderr b/src/test/ui/parser/raw/raw_string.stderr index 5572511881d57..0f1d7e4651deb 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[E0748]: 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 E0748`. From e2738285ea7374bc6423ea6de095ad0e8990975d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 27 Feb 2020 11:12:01 +0100 Subject: [PATCH 4/4] Wording improvement --- src/librustc_error_codes/error_codes/E0748.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0748.md b/src/librustc_error_codes/error_codes/E0748.md index 7743c722eee42..69f1c026125bf 100644 --- a/src/librustc_error_codes/error_codes/E0748.md +++ b/src/librustc_error_codes/error_codes/E0748.md @@ -6,9 +6,11 @@ Erroneous code example: ```compile_fail,E0748 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: +as at the beginning. Example: + ``` -let dolphins = r#"Dolphins!"#; // one `#` at the beginning, one at the end so +let dolphins = r#"Dolphins!"#; // One `#` at the beginning, one at the end so // all good! ```