Skip to content

Commit e9bca51

Browse files
committed
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
2 parents 3f9bddc + e273828 commit e9bca51

File tree

6 files changed

+29
-5
lines changed

6 files changed

+29
-5
lines changed

src/librustc_error_codes/error_codes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ E0744: include_str!("./error_codes/E0744.md"),
418418
E0745: include_str!("./error_codes/E0745.md"),
419419
E0746: include_str!("./error_codes/E0746.md"),
420420
E0747: include_str!("./error_codes/E0747.md"),
421+
E0748: include_str!("./error_codes/E0748.md"),
421422
;
422423
// E0006, // merged with E0005
423424
// E0008, // cannot bind by-move into a pattern guard
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
A raw string isn't correctly terminated because the trailing `#` count doesn't
2+
match its leading `#` count.
3+
4+
Erroneous code example:
5+
6+
```compile_fail,E0748
7+
let dolphins = r##"Dolphins!"#; // error!
8+
```
9+
10+
To terminate a raw string, you have to have the same number of `#` at the end
11+
as at the beginning. Example:
12+
13+
```
14+
let dolphins = r#"Dolphins!"#; // One `#` at the beginning, one at the end so
15+
// all good!
16+
```

src/librustc_parse/lexer/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_data_structures::sync::Lrc;
2-
use rustc_errors::{DiagnosticBuilder, FatalError};
2+
use rustc_errors::{error_code, DiagnosticBuilder, FatalError};
33
use rustc_lexer::unescape;
44
use rustc_lexer::Base;
55
use rustc_session::parse::ParseSess;
@@ -495,7 +495,11 @@ impl<'a> StringReader<'a> {
495495
}
496496

497497
fn report_unterminated_raw_string(&self, start: BytePos, n_hashes: usize) -> ! {
498-
let mut err = self.struct_span_fatal(start, start, "unterminated raw string");
498+
let mut err = self.sess.span_diagnostic.struct_span_fatal_with_code(
499+
self.mk_sp(start, start),
500+
"unterminated raw string",
501+
error_code!(E0748),
502+
);
499503
err.span_label(self.mk_sp(start, start), "unterminated raw string");
500504

501505
if n_hashes > 0 {

src/test/ui/parser/raw-byte-string-eof.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: unterminated raw string
1+
error[E0748]: unterminated raw string
22
--> $DIR/raw-byte-string-eof.rs:2:5
33
|
44
LL | br##"a"#;
@@ -8,3 +8,4 @@ LL | br##"a"#;
88

99
error: aborting due to previous error
1010

11+
For more information about this error, try `rustc --explain E0748`.

src/test/ui/parser/raw-str-unterminated.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: unterminated raw string
1+
error[E0748]: unterminated raw string
22
--> $DIR/raw-str-unterminated.rs:2:5
33
|
44
LL | r#" string literal goes on
@@ -8,3 +8,4 @@ LL | r#" string literal goes on
88

99
error: aborting due to previous error
1010

11+
For more information about this error, try `rustc --explain E0748`.

src/test/ui/parser/raw/raw_string.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: unterminated raw string
1+
error[E0748]: unterminated raw string
22
--> $DIR/raw_string.rs:2:13
33
|
44
LL | let x = r##"lol"#;
@@ -8,3 +8,4 @@ LL | let x = r##"lol"#;
88

99
error: aborting due to previous error
1010

11+
For more information about this error, try `rustc --explain E0748`.

0 commit comments

Comments
 (0)