Add note for unterminated raw string error
This commit is contained in:
@@ -132,6 +132,18 @@ impl<'a> StringReader<'a> {
|
|||||||
self.advance_token()?;
|
self.advance_token()?;
|
||||||
Ok(ret_val)
|
Ok(ret_val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn fail_unterminated_raw_string(&self, pos: BytePos, hash_count: usize) {
|
||||||
|
let mut err = self.struct_span_fatal(pos, pos, "unterminated raw string");
|
||||||
|
err.span_label(self.mk_sp(pos, pos), "unterminated raw string");
|
||||||
|
if hash_count > 0 {
|
||||||
|
err.note(&format!("this raw string should be terminated with `\"{}`",
|
||||||
|
"#".repeat(hash_count)));
|
||||||
|
}
|
||||||
|
err.emit();
|
||||||
|
FatalError.raise();
|
||||||
|
}
|
||||||
|
|
||||||
fn fatal(&self, m: &str) -> FatalError {
|
fn fatal(&self, m: &str) -> FatalError {
|
||||||
self.fatal_span(self.peek_span, m)
|
self.fatal_span(self.peek_span, m)
|
||||||
}
|
}
|
||||||
@@ -269,6 +281,15 @@ impl<'a> StringReader<'a> {
|
|||||||
Self::push_escaped_char_for_msg(&mut m, c);
|
Self::push_escaped_char_for_msg(&mut m, c);
|
||||||
self.fatal_span_(from_pos, to_pos, &m[..])
|
self.fatal_span_(from_pos, to_pos, &m[..])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn struct_span_fatal(&self,
|
||||||
|
from_pos: BytePos,
|
||||||
|
to_pos: BytePos,
|
||||||
|
m: &str)
|
||||||
|
-> DiagnosticBuilder<'a> {
|
||||||
|
self.sess.span_diagnostic.struct_span_fatal(self.mk_sp(from_pos, to_pos), m)
|
||||||
|
}
|
||||||
|
|
||||||
fn struct_fatal_span_char(&self,
|
fn struct_fatal_span_char(&self,
|
||||||
from_pos: BytePos,
|
from_pos: BytePos,
|
||||||
to_pos: BytePos,
|
to_pos: BytePos,
|
||||||
@@ -1404,8 +1425,7 @@ impl<'a> StringReader<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.is_eof() {
|
if self.is_eof() {
|
||||||
let last_bpos = self.pos;
|
self.fail_unterminated_raw_string(start_bpos, hash_count);
|
||||||
self.fatal_span_(start_bpos, last_bpos, "unterminated raw string").raise();
|
|
||||||
} else if !self.ch_is('"') {
|
} else if !self.ch_is('"') {
|
||||||
let last_bpos = self.pos;
|
let last_bpos = self.pos;
|
||||||
let curr_char = self.ch.unwrap();
|
let curr_char = self.ch.unwrap();
|
||||||
@@ -1421,8 +1441,7 @@ impl<'a> StringReader<'a> {
|
|||||||
let mut valid = true;
|
let mut valid = true;
|
||||||
'outer: loop {
|
'outer: loop {
|
||||||
if self.is_eof() {
|
if self.is_eof() {
|
||||||
let last_bpos = self.pos;
|
self.fail_unterminated_raw_string(start_bpos, hash_count);
|
||||||
self.fatal_span_(start_bpos, last_bpos, "unterminated raw string").raise();
|
|
||||||
}
|
}
|
||||||
// if self.ch_is('"') {
|
// if self.ch_is('"') {
|
||||||
// content_end_bpos = self.pos;
|
// content_end_bpos = self.pos;
|
||||||
@@ -1636,8 +1655,7 @@ impl<'a> StringReader<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if self.is_eof() {
|
if self.is_eof() {
|
||||||
let pos = self.pos;
|
self.fail_unterminated_raw_string(start_bpos, hash_count);
|
||||||
self.fatal_span_(start_bpos, pos, "unterminated raw string").raise();
|
|
||||||
} else if !self.ch_is('"') {
|
} else if !self.ch_is('"') {
|
||||||
let pos = self.pos;
|
let pos = self.pos;
|
||||||
let ch = self.ch.unwrap();
|
let ch = self.ch.unwrap();
|
||||||
@@ -1653,8 +1671,7 @@ impl<'a> StringReader<'a> {
|
|||||||
'outer: loop {
|
'outer: loop {
|
||||||
match self.ch {
|
match self.ch {
|
||||||
None => {
|
None => {
|
||||||
let pos = self.pos;
|
self.fail_unterminated_raw_string(start_bpos, hash_count);
|
||||||
self.fatal_span_(start_bpos, pos, "unterminated raw string").raise()
|
|
||||||
}
|
}
|
||||||
Some('"') => {
|
Some('"') => {
|
||||||
content_end_bpos = self.pos;
|
content_end_bpos = self.pos;
|
||||||
|
|||||||
14
src/test/ui/raw_string.rs
Normal file
14
src/test/ui/raw_string.rs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x = r##"lol"#;
|
||||||
|
//~^ ERROR unterminated raw string
|
||||||
|
}
|
||||||
8
src/test/ui/raw_string.stderr
Normal file
8
src/test/ui/raw_string.stderr
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
error: unterminated raw string
|
||||||
|
--> $DIR/raw_string.rs:12:13
|
||||||
|
|
|
||||||
|
LL | let x = r##"lol"#;
|
||||||
|
| ^ unterminated raw string
|
||||||
|
|
|
||||||
|
= note: this raw string should be terminated with `"##`
|
||||||
|
|
||||||
Reference in New Issue
Block a user