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
This commit is contained in:
bors 2020-02-29 13:59:45 +00:00
commit e9bca510fe
6 changed files with 29 additions and 5 deletions

View File

@ -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

View File

@ -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!
```

View File

@ -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 {

View File

@ -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`.

View File

@ -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`.

View File

@ -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`.