]> git.lizzy.rs Git - rust.git/blob - tests/source/chains.rs
0141326269ba75fd3cb7702d395fa2030f729203
[rust.git] / tests / source / chains.rs
1 // rustfmt-normalize_comments: true
2 // rustfmt-use_small_heuristics: false
3 // Test chain formatting.
4
5 fn main() {
6     let a = b .c
7     .d.1
8                 .foo(|x| x + 1);
9
10     bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
11                        .ddddddddddddddddddddddddddd();
12
13     bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc.ddddddddddddddddddddddddddd.eeeeeeee();
14
15     let f = fooooooooooooooooooooooooooooooooooooooooooooooooooo.baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar;
16
17     // Test case where first chain element isn't a path, but is shorter than
18     // the size of a tab.
19     x()
20         .y(|| match cond() { true => (), false => () });
21
22     loong_func()
23         .quux(move || if true {
24             1
25         } else {
26             2
27         });
28
29     some_fuuuuuuuuunction()
30         .method_call_a(aaaaa, bbbbb, |c| {
31             let x = c;
32             x
33         });
34
35     some_fuuuuuuuuunction().method_call_a(aaaaa, bbbbb, |c| {
36         let x = c;
37         x
38     }).method_call_b(aaaaa, bbbbb, |c| {
39         let x = c;
40         x
41     });
42
43     fffffffffffffffffffffffffffffffffff(a,
44                                         {
45                                             SCRIPT_TASK_ROOT
46                                             .with(|root| {
47                                                 *root.borrow_mut()  =   Some(&script_task);
48                                             });
49                                         });                                        
50
51     let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum = xxxxxxx
52         .map(|x| x + 5)
53         .map(|x| x / 2)
54         .fold(0, |acc, x| acc + x);
55
56     aaaaaaaaaaaaaaaa.map(|x| {
57                          x += 1;
58                          x
59                      }).filter(some_mod::some_filter)
60 }
61
62 fn floaters() {
63     let z = Foo {
64         field1: val1,
65         field2: val2,
66     };
67
68     let x = Foo {
69         field1: val1,
70         field2: val2,
71     }.method_call().method_call();
72
73     let y = if cond {
74                 val1
75             } else {
76                 val2
77             }
78                 .method_call();
79
80     {
81         match x {
82             PushParam => {
83                 // params are 1-indexed
84                 stack.push(mparams[match cur.to_digit(10) {
85                     Some(d) => d as usize - 1,
86                     None => return Err("bad param number".to_owned()),
87                 }]
88                                .clone());
89             }
90         }
91     }
92
93     if cond { some(); } else { none(); }
94         .bar()
95         .baz();
96
97     Foo { x: val } .baz(|| { force(); multiline();    }) .quux(); 
98
99     Foo { y: i_am_multi_line, z: ok }
100         .baz(|| {
101             force(); multiline();
102         })
103         .quux(); 
104
105     a + match x { true => "yay!", false => "boo!" }.bar()
106 }
107
108 fn is_replaced_content() -> bool {
109     constellat.send(ConstellationMsg::ViewportConstrained(
110             self.id, constraints)).unwrap();
111 }
112
113 fn issue587() {
114     a.b::<()>(c);
115
116     std::mem::transmute(dl.symbol::<()>("init").unwrap())
117 }
118
119 fn try_shorthand() {
120     let x = expr?;
121     let y = expr.kaas()?.test();
122     let loooooooooooooooooooooooooooooooooooooooooong = does_this?.look?.good?.should_we_break?.after_the_first_question_mark?;
123     let yyyy = expr?.another?.another?.another?.another?.another?.another?.another?.another?.test();
124     let zzzz = expr?.another?.another?.another?.another?;
125     let aaa =  x ????????????  ?????????????? ???? ?????  ?????????????? ?????????  ?????????????? ??;
126
127     let y = a.very .loooooooooooooooooooooooooooooooooooooong()  .chain()
128              .inside()          .weeeeeeeeeeeeeee()? .test()  .0
129         .x;
130
131                 parameterized(f,
132                               substs,
133                               def_id,
134                               Ns::Value,
135                               &[],
136                               |tcx| tcx.lookup_item_type(def_id).generics)?;
137     fooooooooooooooooooooooooooo()?.bar()?.baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz()?;
138 }
139
140 fn issue_1004() {
141          match *self {
142                 ty::ImplOrTraitItem::MethodTraitItem(ref i) => write!(f, "{:?}", i),
143                 ty::ImplOrTraitItem::ConstTraitItem(ref i) => write!(f, "{:?}", i),
144                 ty::ImplOrTraitItem::TypeTraitItem(ref i) => write!(f, "{:?}", i),
145             }
146             ?;
147
148             ty::tls::with(|tcx| {
149                 let tap = ty::Binder(TraitAndProjections(principal, projections));
150                 in_binder(f, tcx, &ty::Binder(""), Some(tap))
151             })
152             ?;
153 }
154
155 fn issue1392() {
156     test_method(r#"
157         if foo {
158             a();
159         }
160         else {
161             b();
162         }
163         "#.trim());
164 }
165
166 // #2067
167 impl Settings {
168     fn save(&self) -> Result<()> {
169         let mut file = File::create(&settings_path).chain_err(|| ErrorKind::WriteError(settings_path.clone()))?;
170     }
171 }
172
173 fn issue2126() {
174     {
175         {
176             {
177                 {
178                     {
179                         let x = self.span_from(sub_span.expect("No span found for struct arant variant"));
180                         self.sspanpan_from_span(sub_span.expect("No span found for struct variant"));
181                         let x = self.spanpan_from_span(sub_span.expect("No span found for struct variant"))?;
182                     }
183                 }
184             }
185         }
186     }
187 }
188
189 // #2200
190 impl Foo {
191     pub fn from_ast(diagnostic: &::errors::Handler,
192                     attrs: &[ast::Attribute]) -> Attributes {
193         let other_attrs = attrs.iter().filter_map(|attr| {
194             attr.with_desugared_doc(|attr| {
195                 if attr.check_name("doc") {
196                     if let Some(mi) = attr.meta() {
197                         if let Some(value) = mi.value_str() {
198                             doc_strings.push(DocFragment::Include(line,
199                                                                   attr.span,
200                                                                   filename,
201                                                                   contents));
202                         }
203                     }
204                 }
205             })
206         }).collect();
207     }
208 }