destructured-fn-argument.rs 10.4 KB
Newer Older
1
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2 3 4 5 6 7 8 9 10
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

11
// ignore-android: FIXME(#10381)
12

13
// compile-flags:-g
14 15 16

// === GDB TESTS ===================================================================================

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
// gdb-command:rbreak zzz
// gdb-command:run

// gdb-command:finish
// gdb-command:print a
// gdb-check:$1 = 1
// gdb-command:print b
// gdb-check:$2 = false
// gdb-command:continue

// gdb-command:finish
// gdb-command:print a
// gdb-check:$3 = 2
// gdb-command:print b
// gdb-check:$4 = 3
// gdb-command:print c
// gdb-check:$5 = 4
// gdb-command:continue

// gdb-command:finish
// gdb-command:print a
// gdb-check:$6 = 5
// gdb-command:print b
// gdb-check:$7 = {6, 7}
// gdb-command:continue

// gdb-command:finish
// gdb-command:print h
// gdb-check:$8 = 8
// gdb-command:print i
// gdb-check:$9 = {a = 9, b = 10}
// gdb-command:print j
// gdb-check:$10 = 11
// gdb-command:continue

// gdb-command:finish
// gdb-command:print k
// gdb-check:$11 = 12
// gdb-command:print l
// gdb-check:$12 = 13
// gdb-command:continue

// gdb-command:finish
// gdb-command:print m
// gdb-check:$13 = 14
// gdb-command:print n
// gdb-check:$14 = 16
// gdb-command:continue

// gdb-command:finish
// gdb-command:print o
// gdb-check:$15 = 18
// gdb-command:continue

// gdb-command:finish
// gdb-command:print p
// gdb-check:$16 = 19
// gdb-command:print q
// gdb-check:$17 = 20
// gdb-command:print r
// gdb-check:$18 = {a = 21, b = 22}
// gdb-command:continue

// gdb-command:finish
// gdb-command:print s
// gdb-check:$19 = 24
// gdb-command:print t
// gdb-check:$20 = 23
// gdb-command:continue

// gdb-command:finish
// gdb-command:print u
// gdb-check:$21 = 25
// gdb-command:print v
// gdb-check:$22 = 26
// gdb-command:print w
// gdb-check:$23 = 27
// gdb-command:print x
// gdb-check:$24 = 28
// gdb-command:print y
// gdb-check:$25 = 29
// gdb-command:print z
// gdb-check:$26 = 30
// gdb-command:print ae
// gdb-check:$27 = 31
// gdb-command:print oe
// gdb-check:$28 = 32
// gdb-command:print ue
// gdb-check:$29 = 33
// gdb-command:continue

// gdb-command:finish
// gdb-command:print aa
// gdb-check:$30 = {34, 35}
// gdb-command:continue

// gdb-command:finish
// gdb-command:print bb
// gdb-check:$31 = {36, 37}
// gdb-command:continue

// gdb-command:finish
// gdb-command:print cc
// gdb-check:$32 = 38
// gdb-command:continue

// gdb-command:finish
// gdb-command:print dd
// gdb-check:$33 = {40, 41, 42}
// gdb-command:continue

// gdb-command:finish
// gdb-command:print *ee
// gdb-check:$34 = {43, 44, 45}
// gdb-command:continue

// gdb-command:finish
// gdb-command:print *ff
// gdb-check:$35 = 46
// gdb-command:print gg
// gdb-check:$36 = {47, 48}
// gdb-command:continue

// gdb-command:finish
// gdb-command:print *hh
// gdb-check:$37 = 50
// gdb-command:continue

// gdb-command:finish
// gdb-command:print ii
// gdb-check:$38 = 51
// gdb-command:continue

// gdb-command:finish
// gdb-command:print *jj
// gdb-check:$39 = 52
// gdb-command:continue

// gdb-command:finish
// gdb-command:print kk
// gdb-check:$40 = 53
// gdb-command:print ll
// gdb-check:$41 = 54
// gdb-command:continue

// gdb-command:finish
// gdb-command:print mm
// gdb-check:$42 = 55
// gdb-command:print *nn
// gdb-check:$43 = 56
// gdb-command:continue

// gdb-command:finish
// gdb-command:print oo
// gdb-check:$44 = 57
// gdb-command:print pp
// gdb-check:$45 = 58
// gdb-command:print qq
// gdb-check:$46 = 59
// gdb-command:continue

// gdb-command:finish
// gdb-command:print rr
// gdb-check:$47 = 60
// gdb-command:print ss
// gdb-check:$48 = 61
// gdb-command:print tt
// gdb-check:$49 = 62
// gdb-command:continue
186

187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334

// === LLDB TESTS ==================================================================================
// lldb-command:run

// lldb-command:print a
// lldb-check:[...]$0 = 1
// lldb-command:print b
// lldb-check:[...]$1 = false
// lldb-command:continue

// lldb-command:print a
// lldb-check:[...]$2 = 2
// lldb-command:print b
// lldb-check:[...]$3 = 3
// lldb-command:print c
// lldb-check:[...]$4 = 4
// lldb-command:continue

// lldb-command:print a
// lldb-check:[...]$5 = 5
// lldb-command:print b
// lldb-check:[...]$6 = (6, 7)
// lldb-command:continue

// lldb-command:print h
// lldb-check:[...]$7 = 8
// lldb-command:print i
// lldb-check:[...]$8 = Struct { a: 9, b: 10 }
// lldb-command:print j
// lldb-check:[...]$9 = 11
// lldb-command:continue

// lldb-command:print k
// lldb-check:[...]$10 = 12
// lldb-command:print l
// lldb-check:[...]$11 = 13
// lldb-command:continue

// lldb-command:print m
// lldb-check:[...]$12 = 14
// lldb-command:print n
// lldb-check:[...]$13 = 16
// lldb-command:continue

// lldb-command:print o
// lldb-check:[...]$14 = 18
// lldb-command:continue

// lldb-command:print p
// lldb-check:[...]$15 = 19
// lldb-command:print q
// lldb-check:[...]$16 = 20
// lldb-command:print r
// lldb-check:[...]$17 = Struct { a: 21, b: 22 }
// lldb-command:continue

// lldb-command:print s
// lldb-check:[...]$18 = 24
// lldb-command:print t
// lldb-check:[...]$19 = 23
// lldb-command:continue

// lldb-command:print u
// lldb-check:[...]$20 = 25
// lldb-command:print v
// lldb-check:[...]$21 = 26
// lldb-command:print w
// lldb-check:[...]$22 = 27
// lldb-command:print x
// lldb-check:[...]$23 = 28
// lldb-command:print y
// lldb-check:[...]$24 = 29
// lldb-command:print z
// lldb-check:[...]$25 = 30
// lldb-command:print ae
// lldb-check:[...]$26 = 31
// lldb-command:print oe
// lldb-check:[...]$27 = 32
// lldb-command:print ue
// lldb-check:[...]$28 = 33
// lldb-command:continue

// lldb-command:print aa
// lldb-check:[...]$29 = (34, 35)
// lldb-command:continue

// lldb-command:print bb
// lldb-check:[...]$30 = (36, 37)
// lldb-command:continue

// lldb-command:print cc
// lldb-check:[...]$31 = 38
// lldb-command:continue

// lldb-command:print dd
// lldb-check:[...]$32 = (40, 41, 42)
// lldb-command:continue

// lldb-command:print *ee
// lldb-check:[...]$33 = (43, 44, 45)
// lldb-command:continue

// lldb-command:print *ff
// lldb-check:[...]$34 = 46
// lldb-command:print gg
// lldb-check:[...]$35 = (47, 48)
// lldb-command:continue

// lldb-command:print *hh
// lldb-check:[...]$36 = 50
// lldb-command:continue

// lldb-command:print ii
// lldb-check:[...]$37 = 51
// lldb-command:continue

// lldb-command:print *jj
// lldb-check:[...]$38 = 52
// lldb-command:continue

// lldb-command:print kk
// lldb-check:[...]$39 = 53
// lldb-command:print ll
// lldb-check:[...]$40 = 54
// lldb-command:continue

// lldb-command:print mm
// lldb-check:[...]$41 = 55
// lldb-command:print *nn
// lldb-check:[...]$42 = 56
// lldb-command:continue

// lldb-command:print oo
// lldb-check:[...]$43 = 57
// lldb-command:print pp
// lldb-check:[...]$44 = 58
// lldb-command:print qq
// lldb-check:[...]$45 = 59
// lldb-command:continue

// lldb-command:print rr
// lldb-check:[...]$46 = 60
// lldb-command:print ss
// lldb-check:[...]$47 = 61
// lldb-command:print tt
// lldb-check:[...]$48 = 62
// lldb-command:continue

335
#![allow(unused_variable)]
336

337

338 339 340 341 342 343 344 345 346
struct Struct {
    a: i64,
    b: i32
}

enum Univariant {
    Unit(i32)
}

D
Daniel Micay 已提交
347
struct TupleStruct (f64, int);
348 349 350


fn simple_tuple((a, b): (int, bool)) {
351
    zzz(); // #break
352 353 354
}

fn nested_tuple((a, (b, c)): (int, (u16, u16))) {
355
    zzz(); // #break
356 357 358
}

fn destructure_only_first_level((a, b): (int, (u32, u32))) {
359
    zzz(); // #break
360 361 362
}

fn struct_as_tuple_element((h, i, j): (i16, Struct, i16)) {
363
    zzz(); // #break
364 365 366
}

fn struct_pattern(Struct { a: k, b: l }: Struct) {
367
    zzz(); // #break
368 369 370
}

fn ignored_tuple_element((m, _, n): (int, u16, i32)) {
371
    zzz(); // #break
372 373
}

A
Alex Crichton 已提交
374
fn ignored_struct_field(Struct { b: o, .. }: Struct) {
375
    zzz(); // #break
376 377 378
}

fn one_struct_destructured_one_not((Struct { a: p, b: q }, r): (Struct, Struct)) {
379
    zzz(); // #break
380 381 382
}

fn different_order_of_struct_fields(Struct { b: s, a: t }: Struct ) {
383
    zzz(); // #break
384 385 386
}

fn complex_nesting(((u,   v  ), ((w,   (x,   Struct { a: y, b: z})), Struct { a: ae, b: oe }), ue ):
D
Derek Guenther 已提交
387 388
                   ((i16, i32), ((i64, (i32, Struct,             )), Struct                 ), u16))
{
389
    zzz(); // #break
390 391
}

392
fn managed_box(&aa: &(int, int)) {
393
    zzz(); // #break
394 395 396
}

fn borrowed_pointer(&bb: &(int, int)) {
397
    zzz(); // #break
398 399 400
}

fn contained_borrowed_pointer((&cc, _): (&int, int)) {
401
    zzz(); // #break
402 403
}

404
fn unique_pointer(box dd: Box<(int, int, int)>) {
405
    zzz(); // #break
406 407 408
}

fn ref_binding(ref ee: (int, int, int)) {
409
    zzz(); // #break
410 411 412
}

fn ref_binding_in_tuple((ref ff, gg): (int, (int, int))) {
413
    zzz(); // #break
414 415
}

A
Alex Crichton 已提交
416
fn ref_binding_in_struct(Struct { b: ref hh, .. }: Struct) {
417
    zzz(); // #break
418 419 420
}

fn univariant_enum(Unit(ii): Univariant) {
421
    zzz(); // #break
422 423 424
}

fn univariant_enum_with_ref_binding(Unit(ref jj): Univariant) {
425
    zzz(); // #break
426 427 428
}

fn tuple_struct(TupleStruct(kk, ll): TupleStruct) {
429
    zzz(); // #break
430 431 432
}

fn tuple_struct_with_ref_binding(TupleStruct(mm, ref nn): TupleStruct) {
433
    zzz(); // #break
434 435 436
}

fn multiple_arguments((oo, pp): (int, int), qq : int) {
437
    zzz(); // #break
438 439 440
}

fn main() {
441
    simple_tuple((1, false));
442 443 444 445 446 447 448 449
    nested_tuple((2, (3, 4)));
    destructure_only_first_level((5, (6, 7)));
    struct_as_tuple_element((8, Struct { a: 9, b: 10 }, 11));
    struct_pattern(Struct { a: 12, b: 13 });
    ignored_tuple_element((14, 15, 16));
    ignored_struct_field(Struct { a: 17, b: 18 });
    one_struct_destructured_one_not((Struct { a: 19, b: 20 }, Struct { a: 21, b: 22 }));
    different_order_of_struct_fields(Struct { a: 23, b: 24 });
450
    complex_nesting(((25, 26), ((27, (28, Struct { a: 29, b: 30})), Struct { a: 31, b: 32 }), 33));
451
    managed_box(&(34, 35));
452 453
    borrowed_pointer(&(36, 37));
    contained_borrowed_pointer((&38, 39));
454
    unique_pointer(box() (40, 41, 42));
455 456 457 458 459 460 461 462 463 464
    ref_binding((43, 44, 45));
    ref_binding_in_tuple((46, (47, 48)));
    ref_binding_in_struct(Struct { a: 49, b: 50 });
    univariant_enum(Unit(51));
    univariant_enum_with_ref_binding(Unit(52));
    tuple_struct(TupleStruct(53.0, 54));
    tuple_struct_with_ref_binding(TupleStruct(55.0, 56));
    multiple_arguments((57, 58), 59);

    fn nested_function(rr: int, (ss, tt): (int, int)) {
465
        zzz(); // #break
466 467 468 469 470
    }

    nested_function(60, (61, 62));
}

471
fn zzz() { () }