summaryrefslogtreecommitdiffstats
path: root/src/test/ui/parser/raw
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/parser/raw
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/parser/raw')
-rw-r--r--src/test/ui/parser/raw/issue-70677-panic-on-unterminated-raw-str-at-eof.rs5
-rw-r--r--src/test/ui/parser/raw/issue-70677-panic-on-unterminated-raw-str-at-eof.stderr9
-rw-r--r--src/test/ui/parser/raw/raw-byte-string-eof.rs3
-rw-r--r--src/test/ui/parser/raw/raw-byte-string-eof.stderr13
-rw-r--r--src/test/ui/parser/raw/raw-byte-string-literals.rs7
-rw-r--r--src/test/ui/parser/raw/raw-byte-string-literals.stderr20
-rw-r--r--src/test/ui/parser/raw/raw-literal-keywords.rs25
-rw-r--r--src/test/ui/parser/raw/raw-literal-keywords.stderr39
-rw-r--r--src/test/ui/parser/raw/raw-literal-self.rs4
-rw-r--r--src/test/ui/parser/raw/raw-literal-self.stderr8
-rw-r--r--src/test/ui/parser/raw/raw-literal-underscore.rs4
-rw-r--r--src/test/ui/parser/raw/raw-literal-underscore.stderr8
-rw-r--r--src/test/ui/parser/raw/raw-str-delim.rs3
-rw-r--r--src/test/ui/parser/raw/raw-str-delim.stderr8
-rw-r--r--src/test/ui/parser/raw/raw-str-in-macro-call.rs14
-rw-r--r--src/test/ui/parser/raw/raw-str-unbalanced.rs22
-rw-r--r--src/test/ui/parser/raw/raw-str-unbalanced.stderr36
-rw-r--r--src/test/ui/parser/raw/raw-str-unterminated.rs4
-rw-r--r--src/test/ui/parser/raw/raw-str-unterminated.stderr11
-rw-r--r--src/test/ui/parser/raw/raw-string-2.rs4
-rw-r--r--src/test/ui/parser/raw/raw-string-2.stderr11
-rw-r--r--src/test/ui/parser/raw/raw-string.rs4
-rw-r--r--src/test/ui/parser/raw/raw-string.stderr13
23 files changed, 275 insertions, 0 deletions
diff --git a/src/test/ui/parser/raw/issue-70677-panic-on-unterminated-raw-str-at-eof.rs b/src/test/ui/parser/raw/issue-70677-panic-on-unterminated-raw-str-at-eof.rs
new file mode 100644
index 000000000..bdfc29a3d
--- /dev/null
+++ b/src/test/ui/parser/raw/issue-70677-panic-on-unterminated-raw-str-at-eof.rs
@@ -0,0 +1,5 @@
+// This won't actually panic because of the error comment -- the `"` needs to be
+// the last byte in the file (including not having a trailing newline)
+// Prior to the fix you get the error: 'expected item, found `r" ...`'
+// because the string being unterminated wasn't properly detected.
+r" //~ unterminated raw string
diff --git a/src/test/ui/parser/raw/issue-70677-panic-on-unterminated-raw-str-at-eof.stderr b/src/test/ui/parser/raw/issue-70677-panic-on-unterminated-raw-str-at-eof.stderr
new file mode 100644
index 000000000..3a7e2a4b1
--- /dev/null
+++ b/src/test/ui/parser/raw/issue-70677-panic-on-unterminated-raw-str-at-eof.stderr
@@ -0,0 +1,9 @@
+error[E0748]: unterminated raw string
+ --> $DIR/issue-70677-panic-on-unterminated-raw-str-at-eof.rs:5:1
+ |
+LL | r"
+ | ^ unterminated raw string
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0748`.
diff --git a/src/test/ui/parser/raw/raw-byte-string-eof.rs b/src/test/ui/parser/raw/raw-byte-string-eof.rs
new file mode 100644
index 000000000..b74907b72
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-byte-string-eof.rs
@@ -0,0 +1,3 @@
+pub fn main() {
+ br##"a"#; //~ unterminated raw string
+}
diff --git a/src/test/ui/parser/raw/raw-byte-string-eof.stderr b/src/test/ui/parser/raw/raw-byte-string-eof.stderr
new file mode 100644
index 000000000..a76668e80
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-byte-string-eof.stderr
@@ -0,0 +1,13 @@
+error[E0748]: unterminated raw string
+ --> $DIR/raw-byte-string-eof.rs:2:5
+ |
+LL | br##"a"#;
+ | ^ - help: consider terminating the string here: `##`
+ | |
+ | unterminated raw string
+ |
+ = note: this raw string should be terminated with `"##`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0748`.
diff --git a/src/test/ui/parser/raw/raw-byte-string-literals.rs b/src/test/ui/parser/raw/raw-byte-string-literals.rs
new file mode 100644
index 000000000..163c8ac66
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-byte-string-literals.rs
@@ -0,0 +1,7 @@
+// ignore-tidy-cr
+
+pub fn main() {
+ br"a "; //~ ERROR bare CR not allowed in raw string
+ br"é"; //~ ERROR raw byte string must be ASCII
+ br##~"a"~##; //~ ERROR only `#` is allowed in raw string delimitation
+}
diff --git a/src/test/ui/parser/raw/raw-byte-string-literals.stderr b/src/test/ui/parser/raw/raw-byte-string-literals.stderr
new file mode 100644
index 000000000..cfc877104
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-byte-string-literals.stderr
@@ -0,0 +1,20 @@
+error: bare CR not allowed in raw string
+ --> $DIR/raw-byte-string-literals.rs:4:9
+ |
+LL | br"a ";
+ | ^
+
+error: raw byte string must be ASCII
+ --> $DIR/raw-byte-string-literals.rs:5:8
+ |
+LL | br"é";
+ | ^ must be ASCII
+
+error: found invalid character; only `#` is allowed in raw string delimitation: ~
+ --> $DIR/raw-byte-string-literals.rs:6:5
+ |
+LL | br##~"a"~##;
+ | ^^^^^
+
+error: aborting due to 3 previous errors
+
diff --git a/src/test/ui/parser/raw/raw-literal-keywords.rs b/src/test/ui/parser/raw/raw-literal-keywords.rs
new file mode 100644
index 000000000..a986980fa
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-literal-keywords.rs
@@ -0,0 +1,25 @@
+fn test_if() {
+ r#if true { } //~ ERROR found keyword `true`
+}
+
+fn test_struct() {
+ r#struct Test; //~ ERROR found `Test`
+}
+
+fn test_union() {
+ r#union Test; //~ ERROR found `Test`
+}
+
+fn test_if_2() {
+ let _ = r#if; //~ ERROR cannot find value `r#if` in this scope
+}
+
+fn test_struct_2() {
+ let _ = r#struct; //~ ERROR cannot find value `r#struct` in this scope
+}
+
+fn test_union_2() {
+ let _ = r#union; //~ ERROR cannot find value `union` in this scope
+}
+
+fn main() {}
diff --git a/src/test/ui/parser/raw/raw-literal-keywords.stderr b/src/test/ui/parser/raw/raw-literal-keywords.stderr
new file mode 100644
index 000000000..f7b6c894a
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-literal-keywords.stderr
@@ -0,0 +1,39 @@
+error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found keyword `true`
+ --> $DIR/raw-literal-keywords.rs:2:10
+ |
+LL | r#if true { }
+ | ^^^^ expected one of 8 possible tokens
+
+error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `Test`
+ --> $DIR/raw-literal-keywords.rs:6:14
+ |
+LL | r#struct Test;
+ | ^^^^ expected one of 8 possible tokens
+
+error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `Test`
+ --> $DIR/raw-literal-keywords.rs:10:13
+ |
+LL | r#union Test;
+ | ^^^^ expected one of 8 possible tokens
+
+error[E0425]: cannot find value `r#if` in this scope
+ --> $DIR/raw-literal-keywords.rs:14:13
+ |
+LL | let _ = r#if;
+ | ^^^^ not found in this scope
+
+error[E0425]: cannot find value `r#struct` in this scope
+ --> $DIR/raw-literal-keywords.rs:18:13
+ |
+LL | let _ = r#struct;
+ | ^^^^^^^^ not found in this scope
+
+error[E0425]: cannot find value `union` in this scope
+ --> $DIR/raw-literal-keywords.rs:22:13
+ |
+LL | let _ = r#union;
+ | ^^^^^^^ not found in this scope
+
+error: aborting due to 6 previous errors
+
+For more information about this error, try `rustc --explain E0425`.
diff --git a/src/test/ui/parser/raw/raw-literal-self.rs b/src/test/ui/parser/raw/raw-literal-self.rs
new file mode 100644
index 000000000..a0c9e24c2
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-literal-self.rs
@@ -0,0 +1,4 @@
+fn main() {
+ let r#self: ();
+ //~^ ERROR `self` cannot be a raw identifier
+}
diff --git a/src/test/ui/parser/raw/raw-literal-self.stderr b/src/test/ui/parser/raw/raw-literal-self.stderr
new file mode 100644
index 000000000..2a40dfe20
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-literal-self.stderr
@@ -0,0 +1,8 @@
+error: `self` cannot be a raw identifier
+ --> $DIR/raw-literal-self.rs:2:9
+ |
+LL | let r#self: ();
+ | ^^^^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/parser/raw/raw-literal-underscore.rs b/src/test/ui/parser/raw/raw-literal-underscore.rs
new file mode 100644
index 000000000..a9d9e13a9
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-literal-underscore.rs
@@ -0,0 +1,4 @@
+fn main() {
+ let r#_: ();
+ //~^ ERROR `_` cannot be a raw identifier
+}
diff --git a/src/test/ui/parser/raw/raw-literal-underscore.stderr b/src/test/ui/parser/raw/raw-literal-underscore.stderr
new file mode 100644
index 000000000..d7a364d85
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-literal-underscore.stderr
@@ -0,0 +1,8 @@
+error: `_` cannot be a raw identifier
+ --> $DIR/raw-literal-underscore.rs:2:9
+ |
+LL | let r#_: ();
+ | ^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/parser/raw/raw-str-delim.rs b/src/test/ui/parser/raw/raw-str-delim.rs
new file mode 100644
index 000000000..2f13893ce
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-str-delim.rs
@@ -0,0 +1,3 @@
+static s: &'static str =
+ r#~"#"~# //~ ERROR found invalid character; only `#` is allowed in raw string delimitation
+;
diff --git a/src/test/ui/parser/raw/raw-str-delim.stderr b/src/test/ui/parser/raw/raw-str-delim.stderr
new file mode 100644
index 000000000..8a04f99a1
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-str-delim.stderr
@@ -0,0 +1,8 @@
+error: found invalid character; only `#` is allowed in raw string delimitation: ~
+ --> $DIR/raw-str-delim.rs:2:5
+ |
+LL | r#~"#"~#
+ | ^^^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/parser/raw/raw-str-in-macro-call.rs b/src/test/ui/parser/raw/raw-str-in-macro-call.rs
new file mode 100644
index 000000000..462c2279f
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-str-in-macro-call.rs
@@ -0,0 +1,14 @@
+// check-pass
+
+macro_rules! m1 {
+ ($tt:tt #) => ()
+}
+
+macro_rules! m2 {
+ ($tt:tt) => ()
+}
+
+fn main() {
+ m1!(r#"abc"##);
+ m2!(r#"abc"#);
+}
diff --git a/src/test/ui/parser/raw/raw-str-unbalanced.rs b/src/test/ui/parser/raw/raw-str-unbalanced.rs
new file mode 100644
index 000000000..38537f8b3
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-str-unbalanced.rs
@@ -0,0 +1,22 @@
+static s: &'static str =
+ 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() {}
diff --git a/src/test/ui/parser/raw/raw-str-unbalanced.stderr b/src/test/ui/parser/raw/raw-str-unbalanced.stderr
new file mode 100644
index 000000000..eac8c06c1
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-str-unbalanced.stderr
@@ -0,0 +1,36 @@
+error: too many `#` when terminating raw string
+ --> $DIR/raw-str-unbalanced.rs:2:10
+ |
+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
+ |
+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
+
diff --git a/src/test/ui/parser/raw/raw-str-unterminated.rs b/src/test/ui/parser/raw/raw-str-unterminated.rs
new file mode 100644
index 000000000..fd3172955
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-str-unterminated.rs
@@ -0,0 +1,4 @@
+static s: &'static str =
+ r#" string literal goes on
+ and on
+ //~^^ ERROR unterminated raw string
diff --git a/src/test/ui/parser/raw/raw-str-unterminated.stderr b/src/test/ui/parser/raw/raw-str-unterminated.stderr
new file mode 100644
index 000000000..077f763f1
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-str-unterminated.stderr
@@ -0,0 +1,11 @@
+error[E0748]: unterminated raw string
+ --> $DIR/raw-str-unterminated.rs:2:5
+ |
+LL | r#" string literal goes on
+ | ^ unterminated raw string
+ |
+ = note: this raw string should be terminated with `"#`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0748`.
diff --git a/src/test/ui/parser/raw/raw-string-2.rs b/src/test/ui/parser/raw/raw-string-2.rs
new file mode 100644
index 000000000..067332d28
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-string-2.rs
@@ -0,0 +1,4 @@
+fn main() {
+ let x = r###"here's a long string"# "# "##;
+ //~^ ERROR unterminated raw string
+}
diff --git a/src/test/ui/parser/raw/raw-string-2.stderr b/src/test/ui/parser/raw/raw-string-2.stderr
new file mode 100644
index 000000000..8bbac9d7b
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-string-2.stderr
@@ -0,0 +1,11 @@
+error[E0748]: unterminated raw string
+ --> $DIR/raw-string-2.rs:2:13
+ |
+LL | let x = r###"here's a long string"# "# "##;
+ | ^ unterminated raw string -- help: consider terminating the string here: `###`
+ |
+ = note: this raw string should be terminated with `"###`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0748`.
diff --git a/src/test/ui/parser/raw/raw-string.rs b/src/test/ui/parser/raw/raw-string.rs
new file mode 100644
index 000000000..84f07c4a9
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-string.rs
@@ -0,0 +1,4 @@
+fn main() {
+ let x = r##"lol"#;
+ //~^ ERROR unterminated raw string
+}
diff --git a/src/test/ui/parser/raw/raw-string.stderr b/src/test/ui/parser/raw/raw-string.stderr
new file mode 100644
index 000000000..b2b853a89
--- /dev/null
+++ b/src/test/ui/parser/raw/raw-string.stderr
@@ -0,0 +1,13 @@
+error[E0748]: unterminated raw string
+ --> $DIR/raw-string.rs:2:13
+ |
+LL | let x = r##"lol"#;
+ | ^ - help: consider terminating the string here: `##`
+ | |
+ | unterminated raw string
+ |
+ = note: this raw string should be terminated with `"##`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0748`.