Skip to content

Commit

Permalink
Auto merge of rust-lang#69260 - GuillaumeGomez:create-E0747-error-cod…
Browse files Browse the repository at this point in the history
…e, r=varkor,estebank

Create E0747 error code for unterminated raw strings

Reopening of rust-lang#66035.

r? @estebank
  • Loading branch information
bors committed Feb 29, 2020
2 parents 3f9bddc + e273828 commit e9bca51
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/librustc_error_codes/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions src/librustc_error_codes/error_codes/E0748.md
Original file line number Diff line number Diff line change
@@ -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!
```
8 changes: 6 additions & 2 deletions src/librustc_parse/lexer/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/parser/raw-byte-string-eof.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: unterminated raw string
error[E0748]: unterminated raw string
--> $DIR/raw-byte-string-eof.rs:2:5
|
LL | br##"a"#;
Expand All @@ -8,3 +8,4 @@ LL | br##"a"#;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0748`.
3 changes: 2 additions & 1 deletion src/test/ui/parser/raw-str-unterminated.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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`.
3 changes: 2 additions & 1 deletion src/test/ui/parser/raw/raw_string.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: unterminated raw string
error[E0748]: unterminated raw string
--> $DIR/raw_string.rs:2:13
|
LL | let x = r##"lol"#;
Expand All @@ -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`.

0 comments on commit e9bca51

Please sign in to comment.