summaryrefslogtreecommitdiffstats
path: root/tests/ui/deref-patterns
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/deref-patterns
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/deref-patterns')
-rw-r--r--tests/ui/deref-patterns/basic.rs17
-rw-r--r--tests/ui/deref-patterns/basic.run.stdout3
-rw-r--r--tests/ui/deref-patterns/default-infer.rs9
-rw-r--r--tests/ui/deref-patterns/gate.rs7
-rw-r--r--tests/ui/deref-patterns/gate.stderr11
-rw-r--r--tests/ui/deref-patterns/refs.rs18
6 files changed, 65 insertions, 0 deletions
diff --git a/tests/ui/deref-patterns/basic.rs b/tests/ui/deref-patterns/basic.rs
new file mode 100644
index 000000000..249716040
--- /dev/null
+++ b/tests/ui/deref-patterns/basic.rs
@@ -0,0 +1,17 @@
+// run-pass
+// check-run-results
+#![feature(string_deref_patterns)]
+
+fn main() {
+ test(Some(String::from("42")));
+ test(Some(String::new()));
+ test(None);
+}
+
+fn test(o: Option<String>) {
+ match o {
+ Some("42") => println!("the answer"),
+ Some(_) => println!("something else?"),
+ None => println!("nil"),
+ }
+}
diff --git a/tests/ui/deref-patterns/basic.run.stdout b/tests/ui/deref-patterns/basic.run.stdout
new file mode 100644
index 000000000..e50df0582
--- /dev/null
+++ b/tests/ui/deref-patterns/basic.run.stdout
@@ -0,0 +1,3 @@
+the answer
+something else?
+nil
diff --git a/tests/ui/deref-patterns/default-infer.rs b/tests/ui/deref-patterns/default-infer.rs
new file mode 100644
index 000000000..050b84730
--- /dev/null
+++ b/tests/ui/deref-patterns/default-infer.rs
@@ -0,0 +1,9 @@
+// check-pass
+#![feature(string_deref_patterns)]
+
+fn main() {
+ match <_ as Default>::default() {
+ "" => (),
+ _ => unreachable!(),
+ }
+}
diff --git a/tests/ui/deref-patterns/gate.rs b/tests/ui/deref-patterns/gate.rs
new file mode 100644
index 000000000..ff50e30de
--- /dev/null
+++ b/tests/ui/deref-patterns/gate.rs
@@ -0,0 +1,7 @@
+// gate-test-string_deref_patterns
+fn main() {
+ match String::new() {
+ "" | _ => {}
+ //~^ mismatched types
+ }
+}
diff --git a/tests/ui/deref-patterns/gate.stderr b/tests/ui/deref-patterns/gate.stderr
new file mode 100644
index 000000000..993468b5e
--- /dev/null
+++ b/tests/ui/deref-patterns/gate.stderr
@@ -0,0 +1,11 @@
+error[E0308]: mismatched types
+ --> $DIR/gate.rs:4:9
+ |
+LL | match String::new() {
+ | ------------- this expression has type `String`
+LL | "" | _ => {}
+ | ^^ expected struct `String`, found `&str`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/deref-patterns/refs.rs b/tests/ui/deref-patterns/refs.rs
new file mode 100644
index 000000000..97e260d27
--- /dev/null
+++ b/tests/ui/deref-patterns/refs.rs
@@ -0,0 +1,18 @@
+// check-pass
+#![feature(string_deref_patterns)]
+
+fn foo(s: &String) -> i32 {
+ match *s {
+ "a" => 42,
+ _ => -1,
+ }
+}
+
+fn bar(s: Option<&&&&String>) -> i32 {
+ match s {
+ Some(&&&&"&&&&") => 1,
+ _ => -1,
+ }
+}
+
+fn main() {}