diff options
| author | bors <bors@rust-lang.org> | 2020-02-29 13:59:45 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-02-29 13:59:45 +0000 |
| commit | e9bca510fe17354f876aa289bb39d347d7c69c69 (patch) | |
| tree | 40659d608c96e6f87d8d1951f983e4dfe2886135 /src | |
| parent | 3f9bddc7fea3ca1d49f39f22bb937a84ed32f84e (diff) | |
| parent | e2738285ea7374bc6423ea6de095ad0e8990975d (diff) | |
| download | rust-e9bca510fe17354f876aa289bb39d347d7c69c69.tar.gz rust-e9bca510fe17354f876aa289bb39d347d7c69c69.zip | |
Auto merge of #69260 - GuillaumeGomez:create-E0747-error-code, r=varkor,estebank
Create E0747 error code for unterminated raw strings Reopening of #66035. r? @estebank
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_error_codes/error_codes.rs | 1 | ||||
| -rw-r--r-- | src/librustc_error_codes/error_codes/E0748.md | 16 | ||||
| -rw-r--r-- | src/librustc_parse/lexer/mod.rs | 8 | ||||
| -rw-r--r-- | src/test/ui/parser/raw-byte-string-eof.stderr | 3 | ||||
| -rw-r--r-- | src/test/ui/parser/raw-str-unterminated.stderr | 3 | ||||
| -rw-r--r-- | src/test/ui/parser/raw/raw_string.stderr | 3 |
6 files changed, 29 insertions, 5 deletions
diff --git a/src/librustc_error_codes/error_codes.rs b/src/librustc_error_codes/error_codes.rs index 91a7b6c8958..89359bb1bfd 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_error_codes/error_codes/E0748.md b/src/librustc_error_codes/error_codes/E0748.md new file mode 100644 index 00000000000..69f1c026125 --- /dev/null +++ b/src/librustc_error_codes/error_codes/E0748.md @@ -0,0 +1,16 @@ +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 +as at the beginning. Example: + +``` +let dolphins = r#"Dolphins!"#; // One `#` at the beginning, one at the end so + // all good! +``` diff --git a/src/librustc_parse/lexer/mod.rs b/src/librustc_parse/lexer/mod.rs index 66280638a2d..face0e67992 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 { diff --git a/src/test/ui/parser/raw-byte-string-eof.stderr b/src/test/ui/parser/raw-byte-string-eof.stderr index 65fa89f2a81..d5f22e2a1a8 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 67792eb91e5..077f763f154 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 5572511881d..0f1d7e4651d 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`. |
