]> git.lizzy.rs Git - rust.git/blob - src/tools/rustfmt/tests/source/pattern.rs
Rollup merge of #107166 - petrochenkov:nooptable, r=oli-obk
[rust.git] / src / tools / rustfmt / tests / source / pattern.rs
1 // rustfmt-normalize_comments: true
2 #![feature(exclusive_range_pattern)]
3 use core::u8::MAX;
4
5 fn main() {
6     let z = match x {
7         "pat1" => 1,
8         ( ref  x, ref  mut  y /*comment*/) => 2,
9     };
10
11     if let <  T as  Trait   > :: CONST = ident {
12         do_smth();
13     }
14
15     let Some ( ref   xyz  /*   comment!   */) = opt;
16
17     if let  None  =   opt2 { panic!("oh noes"); }
18
19     let foo@bar (f) = 42;
20     let a::foo ( ..) = 42;
21     let [ ] = 42;
22     let [a,     b,c ] = 42;
23     let [ a,b,c ] = 42;
24     let [a,    b, c, d,e,f,     g] = 42;
25     let foo {   } = 42;
26     let foo {..} = 42;
27     let foo { x, y: ref foo,     .. } = 42;
28     let foo { x, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: ref foo,     .. } = 42;
29     let foo { x,       yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: ref foo,      } = 42;
30     let foo { x, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: ref foo,     .. };
31     let foo { x,       yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: ref foo,      };
32
33     match b"12" {
34         [0,
35         1..MAX
36         ] => {}
37         _ => {}
38     }
39 }
40
41 impl<'a,'b> ResolveGeneratedContentFragmentMutator<'a,'b> {
42     fn mutate_fragment(&mut self, fragment: &mut Fragment) {
43         match **info {
44             GeneratedContentInfo::ContentItem(
45                 ContentItem::Counter(
46                     ref counter_name,
47                     counter_style
48                 )
49             ) => {}}}
50 }
51
52 fn issue_1319() {
53     if let (Event { .. }, .. ) = ev_state {}
54 }
55
56 fn issue_1874() {
57     if let Some(()) = x {
58 y
59     }
60 }
61
62 fn combine_patterns() {
63     let x = match y {
64         Some(
65             Some(
66                 Foo {
67                     z: Bar(..),
68                     a: Bar(..),
69                     b: Bar(..),
70                 },
71             ),
72         ) => z,
73         _ => return,
74     };
75 }
76
77 fn slice_patterns() {
78     match b"123" {
79         [0, ..] => {}
80         [0, foo] => {}
81         _ => {}
82     }
83 }
84
85 fn issue3728() {
86     let foo = |
87     (c,)
88         | c;
89     foo((1,));
90 }