From 64d98f8ee037282c35007b64c2649055c56af1db Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:03 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/deref-patterns/basic.rs | 17 +++++++++++++++++ tests/ui/deref-patterns/basic.run.stdout | 3 +++ tests/ui/deref-patterns/default-infer.rs | 9 +++++++++ tests/ui/deref-patterns/gate.rs | 7 +++++++ tests/ui/deref-patterns/gate.stderr | 11 +++++++++++ tests/ui/deref-patterns/refs.rs | 18 ++++++++++++++++++ 6 files changed, 65 insertions(+) create mode 100644 tests/ui/deref-patterns/basic.rs create mode 100644 tests/ui/deref-patterns/basic.run.stdout create mode 100644 tests/ui/deref-patterns/default-infer.rs create mode 100644 tests/ui/deref-patterns/gate.rs create mode 100644 tests/ui/deref-patterns/gate.stderr create mode 100644 tests/ui/deref-patterns/refs.rs (limited to 'tests/ui/deref-patterns') 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) { + 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() {} -- cgit v1.2.3