File: coroutine-objects.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (89 lines) | stat: -rw-r--r-- 3,034 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
//@ min-lldb-version: 1800

// LLDB (18.1+) now supports DW_TAG_variant_part, but there is some bug in either compiler or LLDB
// with memory layout of discriminant for this particular enum
// ensure that LLDB won't crash at least (like #57822).

//@ compile-flags:-g

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

// gdb-command:run
// gdb-command:print b
// gdb-check:$1 = coroutine_objects::main::{coroutine_env#0}::Unresumed{_ref__a: 0x[...]}
// gdb-command:continue
// gdb-command:print b
// gdb-check:$2 = coroutine_objects::main::{coroutine_env#0}::Suspend0{c: 6, d: 7, _ref__a: 0x[...]}
// gdb-command:continue
// gdb-command:print b
// gdb-check:$3 = coroutine_objects::main::{coroutine_env#0}::Suspend1{c: 7, d: 8, _ref__a: 0x[...]}
// gdb-command:continue
// gdb-command:print b
// gdb-check:$4 = coroutine_objects::main::{coroutine_env#0}::Returned{_ref__a: 0x[...]}

// === LLDB TESTS ==================================================================================

// lldb-command:run
// lldb-command:v b
// lldb-check:(coroutine_objects::main::{coroutine_env#0}) b = { value = { _ref__a = 0x[...] } $discr$ = [...] }

// === CDB TESTS ===================================================================================

// cdb-command: g
// cdb-command: dx b
// cdb-check: b                : Unresumed [Type: enum2$<coroutine_objects::main::coroutine_env$0>]
// cdb-check:    [+0x[...]] _ref__a          : 0x[...] : 5 [Type: int *]

// cdb-command: g
// cdb-command: dx b
// cdb-check: b                : Suspend0 [Type: enum2$<coroutine_objects::main::coroutine_env$0>]
// cdb-check:    [+0x[...]] c                : 6 [Type: int]
// cdb-check:    [+0x[...]] d                : 7 [Type: int]
// cdb-check:    [+0x[...]] _ref__a          : 0x[...] : 5 [Type: int *]

// cdb-command: g
// cdb-command: dx b
// cdb-check: b                : Suspend1 [Type: enum2$<coroutine_objects::main::coroutine_env$0>]
// cdb-check:    [+0x[...]] c                : 7 [Type: int]
// cdb-check:    [+0x[...]] d                : 8 [Type: int]
// cdb-check:    [+0x[...]] _ref__a          : 0x[...] : 6 [Type: int *]

// cdb-command: g
// cdb-command: dx b
// cdb-check: b                : Returned [Type: enum2$<coroutine_objects::main::coroutine_env$0>]
// cdb-check:    [+0x[...]] _ref__a          : 0x[...] : 6 [Type: int *]

#![feature(omit_gdb_pretty_printer_section, coroutines, coroutine_trait, stmt_expr_attributes)]
#![omit_gdb_pretty_printer_section]

use std::ops::Coroutine;
use std::pin::Pin;

fn main() {
    let mut a = 5;
    let mut b = #[coroutine]
    || {
        let mut c = 6;
        let mut d = 7;

        yield;
        a += 1;
        c += 1;
        d += 1;

        yield;
        println!("{} {} {}", a, c, d);
    };
    _zzz(); // #break
    Pin::new(&mut b).resume(());
    _zzz(); // #break
    Pin::new(&mut b).resume(());
    _zzz(); // #break
    Pin::new(&mut b).resume(());
    _zzz(); // #break
}

#[inline(never)]
fn _zzz() {
    ()
}