]> git.lizzy.rs Git - rust.git/blob - src/test/ui/binding/match-borrowed_str.rs
Auto merge of #99612 - yanchen4791:issue-95079-fix, r=compiler-errors
[rust.git] / src / test / ui / binding / match-borrowed_str.rs
1 // run-pass
2
3 fn f1(ref_string: &str) -> String {
4     match ref_string {
5         "a" => "found a".to_string(),
6         "b" => "found b".to_string(),
7         _ => "not found".to_string()
8     }
9 }
10
11 fn f2(ref_string: &str) -> String {
12     match ref_string {
13         "a" => "found a".to_string(),
14         "b" => "found b".to_string(),
15         s => format!("not found ({})", s)
16     }
17 }
18
19 fn g1(ref_1: &str, ref_2: &str) -> String {
20     match (ref_1, ref_2) {
21         ("a", "b") => "found a,b".to_string(),
22         ("b", "c") => "found b,c".to_string(),
23         _ => "not found".to_string()
24     }
25 }
26
27 fn g2(ref_1: &str, ref_2: &str) -> String {
28     match (ref_1, ref_2) {
29         ("a", "b") => "found a,b".to_string(),
30         ("b", "c") => "found b,c".to_string(),
31         (s1, s2) => format!("not found ({}, {})", s1, s2)
32     }
33 }
34
35 pub fn main() {
36     assert_eq!(f1("b"), "found b".to_string());
37     assert_eq!(f1("c"), "not found".to_string());
38     assert_eq!(f1("d"), "not found".to_string());
39     assert_eq!(f2("b"), "found b".to_string());
40     assert_eq!(f2("c"), "not found (c)".to_string());
41     assert_eq!(f2("d"), "not found (d)".to_string());
42     assert_eq!(g1("b", "c"), "found b,c".to_string());
43     assert_eq!(g1("c", "d"), "not found".to_string());
44     assert_eq!(g1("d", "e"), "not found".to_string());
45     assert_eq!(g2("b", "c"), "found b,c".to_string());
46     assert_eq!(g2("c", "d"), "not found (c, d)".to_string());
47     assert_eq!(g2("d", "e"), "not found (d, e)".to_string());
48 }