Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create E0744 error code for unterminated raw string error #66035

Closed
Closed
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
18 changes: 18 additions & 0 deletions src/libsyntax/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A raw string isn't terminated.
A raw string isn't correctly terminated because the trailing `#` count doesn't match its leading `#` count.


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
Expand Down
6 changes: 4 additions & 2 deletions src/libsyntax/parse/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
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[E0744]: 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 E0744`.
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[E0744]: 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 E0744`.
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[E0744]: 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 E0744`.