Better handle too many # recovery in raw str

Point at all the unnecessary trailing `#`.
Better handle interaction with outer attributes when `;` is missing.

Fix #95030.
This commit is contained in:
Esteban Küber 2022-04-23 19:44:25 -07:00
parent 1e9aa8a96b
commit 3587406967
3 changed files with 85 additions and 16 deletions

View file

@ -1,4 +1,22 @@
static s: &'static str =
r#"
"## //~ too many `#` when terminating raw string
r#""## //~ ERROR too many `#` when terminating raw string
;
static s2: &'static str =
r#"
"#### //~ ERROR too many `#` when terminating raw string
;
const A: &'static str = r"" //~ ERROR expected `;`, found `#`
// Test
#[test]
fn test() {}
const B: &'static str = r""## //~ ERROR too many `#` when terminating raw string
// Test
#[test]
fn test2() {}
fn main() {}

View file

@ -1,10 +1,36 @@
error: too many `#` when terminating raw string
--> $DIR/raw-str-unbalanced.rs:3:9
--> $DIR/raw-str-unbalanced.rs:2:10
|
LL | "##
| ^ help: remove the extra `#`
LL | r#""##
| -----^ help: remove the extra `#`
| |
| this raw string started with 1 `#`
error: too many `#` when terminating raw string
--> $DIR/raw-str-unbalanced.rs:7:9
|
= note: the raw string started with 1 `#`s
LL | / r#"
LL | | "####
| | -^^^ help: remove the extra `#`s
| |________|
| this raw string started with 1 `#`
error: aborting due to previous error
error: expected `;`, found `#`
--> $DIR/raw-str-unbalanced.rs:10:28
|
LL | const A: &'static str = r""
| ^ help: add `;` here
...
LL | #[test]
| - unexpected token
error: too many `#` when terminating raw string
--> $DIR/raw-str-unbalanced.rs:16:28
|
LL | const B: &'static str = r""##
| ---^^ help: remove the extra `#`s
| |
| this raw string started with 0 `#`s
error: aborting due to 4 previous errors