From 35874069679cf394e8a93bd5764ce13f9696096b Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Sat, 23 Apr 2022 19:44:25 -0700 Subject: 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. --- src/test/ui/parser/raw/raw-str-unbalanced.rs | 20 ++++++++++++- src/test/ui/parser/raw/raw-str-unbalanced.stderr | 36 ++++++++++++++++++++---- 2 files changed, 50 insertions(+), 6 deletions(-) (limited to 'src/test/ui/parser') diff --git a/src/test/ui/parser/raw/raw-str-unbalanced.rs b/src/test/ui/parser/raw/raw-str-unbalanced.rs index 35f118f5ce6..38537f8b31e 100644 --- a/src/test/ui/parser/raw/raw-str-unbalanced.rs +++ b/src/test/ui/parser/raw/raw-str-unbalanced.rs @@ -1,4 +1,22 @@ static s: &'static str = + r#""## //~ ERROR too many `#` when terminating raw string +; + +static s2: &'static str = r#" - "## //~ too many `#` when terminating raw string + "#### //~ 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() {} diff --git a/src/test/ui/parser/raw/raw-str-unbalanced.stderr b/src/test/ui/parser/raw/raw-str-unbalanced.stderr index bf8f3a7a5a4..eac8c06c1df 100644 --- a/src/test/ui/parser/raw/raw-str-unbalanced.stderr +++ b/src/test/ui/parser/raw/raw-str-unbalanced.stderr @@ -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 + | +LL | / r#" +LL | | "#### + | | -^^^ help: remove the extra `#`s + | |________| + | this raw string started with 1 `#` + +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 | - = note: the raw string started with 1 `#`s +LL | const B: &'static str = r""## + | ---^^ help: remove the extra `#`s + | | + | this raw string started with 0 `#`s -error: aborting due to previous error +error: aborting due to 4 previous errors -- cgit 1.4.1-3-g733a5