Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`.