Improve error messages for raw strings (#60762)
This diff improves error messages around raw strings in a few ways: - Catch extra trailing `#` in the parser. This can't be handled in the lexer because we could be in a macro that actually expects another # (see test) - Refactor & unify error handling in the lexer between ByteStrings and RawByteStrings - Detect potentially intended terminators (longest sequence of "#*" is suggested)
This commit is contained in:
parent
840a5769b0
commit
629e97a5a0
10 changed files with 344 additions and 63 deletions
|
|
@ -2,7 +2,9 @@ error[E0748]: unterminated raw string
|
|||
--> $DIR/raw-byte-string-eof.rs:2:5
|
||||
|
|
||||
LL | br##"a"#;
|
||||
| ^ unterminated raw string
|
||||
| ^ - help: you might have intended to terminate the string here: `##`
|
||||
| |
|
||||
| unterminated raw string
|
||||
|
|
||||
= note: this raw string should be terminated with `"##`
|
||||
|
||||
|
|
|
|||
14
src/test/ui/parser/raw/raw-str-in-macro-call.rs
Normal file
14
src/test/ui/parser/raw/raw-str-in-macro-call.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
// check-pass
|
||||
|
||||
macro_rules! m1 {
|
||||
($tt:tt #) => ()
|
||||
}
|
||||
|
||||
macro_rules! m2 {
|
||||
($tt:tt) => ()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
m1!(r#"abc"##);
|
||||
m2!(r#"abc"#);
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
static s: &'static str =
|
||||
r#"
|
||||
"## //~ ERROR expected one of `.`, `;`, `?`, or an operator, found `#`
|
||||
"## //~ too many `#` when terminating raw string
|
||||
;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
error: expected one of `.`, `;`, `?`, or an operator, found `#`
|
||||
error: too many `#` when terminating raw string
|
||||
--> $DIR/raw-str-unbalanced.rs:3:9
|
||||
|
|
||||
LL | "##
|
||||
| ^ expected one of `.`, `;`, `?`, or an operator
|
||||
| ^ help: Remove the extra `#`
|
||||
|
|
||||
= note: The raw string started with 1 `#`s
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ error[E0748]: unterminated raw string
|
|||
--> $DIR/raw_string.rs:2:13
|
||||
|
|
||||
LL | let x = r##"lol"#;
|
||||
| ^ unterminated raw string
|
||||
| ^ - help: you might have intended to terminate the string here: `##`
|
||||
| |
|
||||
| unterminated raw string
|
||||
|
|
||||
= note: this raw string should be terminated with `"##`
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue